Tags:
create new tag
view all tags

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 | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2003-12-19 - MichaelSparks
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.