r4 - 19 Dec 2003 - 14:49:00 - MichaelSparksYou are here: TWiki >  Codev Web > UrlParamNeedsToAcceptDefaultValue
Tags:
, create new tag

Proposal: URLPARAM should accept a default value if not provided

In many cases a bare %URLPARAM{"variable"}% is useful, however in some parameterising works better in conjunction with a default variable - for example a default section, a default topic - eg:

  • %INCLUDE{"%URLPARAM\{'tutorial' default='TutorialList'}\%" section="%URLPARAM\{'tutorialsection' default='introduction'}\%" }%

Usage

URLPARAM is extended to have the following extra optional attribute:

  • %URLPARAM{"somecgiparam" default="default value"}%

Implementation

Implementation is relatively trivial, but has clear uses. (Aside from the example noted above).


This is implemented, see UrlParamWithDefaultValue.
Removed extraneous comments (hopefully OK). The point is this feature is implemented, albeit slightly differently from my implementation. (Posted below for comparison) I've found some cases where the implementation below has been more useful than the one in CVS due to where the conditions are applied.

Alternative implementation (not a patch since just for comparison of ideas):

sub handleUrlParam
{
    my( $theArgs ) = @_;
...
    my $param   = extractNameValuePair( $theArgs );
    my $newLine = extractNameValuePair( $theArgs, "newline" ) || "";
    my $value = "";
    if( $cgiQuery ) {
...
        unless( $value ) {
           $value = extractNameValuePair( $theArgs, "default" )|| "";
        }
    }
    return $value;
}
vs
sub handleUrlParam
{
    my( $theArgs ) = @_;
...
    my $param   = extractNameValuePair( $theArgs );
    my $newLine = extractNameValuePair( $theArgs, "newline" ) || "";
    my $value = "";
    if( $cgiQuery ) {
...
    }
    unless( $value ) {
        $value = extractNameValuePair( $theArgs, "default" )|| "";
    }
    return $value;
}

Subtle, but crucial difference.

Contributors

(Hope this is OK)

-- MS - 19, 28 Aug 2003, 19 Dec 2003
-- PeterThoeny - 29 Aug 2003

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r4 < r3 < r2 < r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback SourceForge.net Logo