Help:Parameter default: Difference between revisions

Content deleted Content added
m Repetition: syntaxhighlight lang="moin"
 
(4 intermediate revisions by 3 users not shown)
Line 16:
The expression for the parameter name can also contain <code>|</code>, as part of full template or parameter syntax within it.
 
Examples, using <code><nowiki>{{x3}}</nowiki></code> containing <syntaxhighlight lang="moinwikitext" inline>{{{1}}}{{{1}}}{{{1}}}</syntaxhighlight> and <syntaxhighlight lang="moinwikitext" inline>{{t2}}</syntaxhighlight> containing <syntaxhighlight lang="moinwikitext" inline>start-{{{1}}}-middle-{{{2}}}-end</syntaxhighlight>:
*<syntaxhighlight lang="moinwikitext" inline>{{{a|b|c|d}}}</syntaxhighlight> gives <code>{{{A|b|c|d}}}</code>
*<syntaxhighlight lang="textwikitext" inline>{{{a|{{x3|b}}}}}</syntaxhighlight> gives <code>{{{A|bbb}}}</code>
*<syntaxhighlight lang="textwikitext" inline>{{{a|{{{b|c}}}}}}</syntaxhighlight> gives <code>{{{A|{{{b|c}}}}}}</code>
*<syntaxhighlight lang="moinwikitext" inline>{{{a|[[b|c]]}}}</syntaxhighlight> gives <code>{{{A|[[b|c]]}}}</code>
*<syntaxhighlight lang="moinwikitext" inline>{{{{{x3|a}}|b}}}</syntaxhighlight> gives <code>{{{aaa|b}}}</code> - parameter aaa is undefined
*<syntaxhighlight lang="textwikitext" inline>{{{{{{a|b}}}|c}}}</syntaxhighlight> gives <code>{{{{{{A|b}}}|c}}}</code> - parameter b is undefined
 
*<syntaxhighlight lang="moinwikitext" inline>{{{a|<nowiki>b|c</nowiki>}}}</syntaxhighlight> gives <code>{{{A|<nowiki>b|c</nowiki>}}}</code> - works fine for rendering text, but is not suitable for putting parameters b and c in a template call (there is no function for removing nowiki tags):
*:<syntaxhighlight lang="moinwikitext" inline>{{t2|{{{a|<nowiki>b|c</nowiki>}}}}}</syntaxhighlight> gives <code>start-b|c-middle-{{{2}}}-end</code>
 
*<syntaxhighlight lang="moinwikitext" inline>{{{a|b{{!}}c}}}</syntaxhighlight> gives <code>{{{a|b{{!}}c}}}</code>, and the bar will be interpreted by the next layer of templates.
 
==Expressions containing a parameter, with default==
Line 61:
For comparison using a="if" and c=d="", and also the shorter class name "if" instead of "HiddenStructure", the two lines are:
 
<syntaxhighlight lang="wikitext">
<nowiki><span class=" if{{{b|}}} "> ... </span></nowiki>
<nowiki>{{{ span class=" if{{{b|}}} | "> ... }}}</nowikispan>
{{{ if{{{b|}}} | ... }}}
 
</syntaxhighlight>
In the second method the wikitext in the template is 15 characters shorter for each optional item, but each call is 4 characters ("if=|") longer.
 
Line 73 ⟶ 74:
{{Tim|fors}}, containing:
----
<syntaxhighlight lang="moinwikitext">{{fors/aux
|v@=
|c={{{call}}}
Line 87 ⟶ 88:
with {{Tim|fors/aux}}, containing:
----
<syntaxhighlight lang="textwikitext">{{{v{{{1}}}|{{{{{c}}}|{{{pc1}}}|{{{pc2}}}|{{{pc3}}}|{{{pc4}}}|{{{pv}}}={{{1}}}}}}}}
{{{v{{{2}}}|{{{s}}}{{{{{c}}}|{{{pc1}}}|{{{pc2}}}|{{{pc3}}}|{{{pc4}}}|{{{pv}}}={{{2}}}}}}}}
{{{v{{{3}}}|{{{s}}}{{{{{c}}}|{{{pc1}}}|{{{pc2}}}|{{{pc3}}}|{{{pc4}}}|{{{pv}}}={{{3}}}}}}}}</syntaxhighlight>
Line 94 ⟶ 95:
In short form the latter consists of components
 
<syntaxhighlight lang="moinwikitext">[ v[''i''] | [s] {{[c]|[pc1]|[pc2]|[pc3]|[pc4]|[pv]=[''i'']}} ]</syntaxhighlight> (''i'' = 1, 2, 3, for ''i'' = 1 without [s])
 
or in terms of the parameters of the first template:
 
<syntaxhighlight lang="moinwikitext">[v[''i''|@] | [sep|] {{[call]|[pc1|]|[pc2|]|[pc3|]|[pc4|]|[pv|1]=[''i'']}} ]</syntaxhighlight>
 
This is indeed of the above-mentioned form <code>[a[b|c]|f([b])]</code>, with {{mono|1=a=v, b=''i'', c=@}}, and
 
<syntaxhighlight lang="moinwikitext">f(x) = [sep|] {{[call]|[pc1|]|[pc2|]|[pc3|]|[pc4|]|[pv|1]=x}}</syntaxhighlight>
 
The assumptions mentioned above apply for d equal to null, and provided that no [''i''] is equal to "@".
Line 108 ⟶ 109:
===Variations===
Since {{code|1=v@=null}} we can also take make the concatenation the outer operation:
<syntaxhighlight lang="moinwikitext">[v[''i''|@] | [sep|]] [v[''i''|@] | {{[call]|[pc1|]|[pc2|]|[pc3|]|[pc4|]|[pv|1]=[''i'']}} ]</syntaxhighlight>
 
==Conditional statement==
{{Tim|if}} contains:
----
<presyntaxhighlight lang="wikitext">{{{else{{{test|}}}|{{{test{{{test|}}}|{{{then|}}}}}}}}}</presyntaxhighlight>
----
 
 
or in short form:
 
<syntaxhighlight lang="text">[ else[test|] | [ test[test|] | [then|] ] ]</syntaxhighlight>
 
If [<code>{{bracket|test]}}</code> is defined this reduces to
 
<syntaxhighlight lang="text">[ else[test] | [ test[test] | [then|] ] ]</syntaxhighlight>
 
For test equal to null this reduces to [else<code>{{bracket|]else{{!}}}}</code>; otherwise, if no parameter name starting with "test" or "else" applies except these themselves, then this reduces to [then<code>{{bracket|]then{{!}}}}</code>.
 
If [<code>{{bracket|test]}}</code> is undefined we get
 
<syntaxhighlight lang="text">[ else | [then|] ]</syntaxhighlight>
 
==Last-but technique==