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