User:Wnt/Templates/Parameters

Parameters are fully cased; spaces don't matter before named parameters

edit

{{#invoke:Wnt/Templates/Parameters | main | aa = bb | aA = bB|Aa=Bb|AA=BB|unnamed#1|unnamed#2}}

aa = bb
aA = bB
Aa = Bb
AA = BB
Unnamed parameters are:
#1 = unnamed#1
#2 = unnamed#2

Omitting parameters and repeating them back (returning "frame.args.AA") leads to errors when they're simply returned if it isn't handled otherwise

edit

{{#invoke:Wnt/Templates/Parameters | main | aa = bb | aA = bB|Aa=Bb|unnamed#1|unnamed#2}}

Lua error in Module:Wnt/Templates/Parameters at line 3: attempt to concatenate field 'AA' (a nil value).

Recovering using "or"

edit

To avoid those errors, any parameter test can simply be combined with or - i.e. (frame.args.aa or "default text"). As explained in Extension:Scribunto/Lua_reference_manual#Logical_Operators, "or" and "and" are indeed standard logical operators (so parentheses around them work, for example). The reason why they work is that the apparently empty parameters are set to nil or false (I assume nil); apparently returning nil is the source of the error.

{{#invoke:Wnt/Templates/Parameters | recoverable | aa = bb | aA = bB|Aa=Bb|unnamed#1|unnamed#2}}

aa = bb
aA = bB
Aa = Bb
AA = NO AA
Unnamed parameters are:
#1 = unnamed#1
#2 = unnamed#2

Another feature to demonstrate here is that the part after "and" or "or" can be a function, which is evaluated only if necessary to determine the value ... I should figure out what kind of mischief this can be used to trigger...

Passing in empty parameters is different from passing in no parameters

edit

{{#invoke:Wnt/Templates/Parameters | recoverable | aA =|Aa= | }}

aa = NO aa
aA =
Aa =
AA = NO AA
Unnamed parameters are:
#1 =
#2 = NO #2