Help:Parameter default: Difference between revisions

Content deleted Content added
m top: semantic tags
 
(7 intermediate revisions by 3 users not shown)
Line 12:
 
==Limitation==
In the case of multiple default parts, only the first applies: <code>[a|b|c|d]</code> is equivalent with <code>[a|b]</code>. The default part can only contain "<code>|"</code> as part of full template, parameter or link syntax within it, and within {{xtag|nowiki-tags}}. Note that "<code>|"</code> can be avoided in table syntax by applying HTML coding (element "<nowiki><{{tag|table></nowiki>"}}).
 
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 <code><nowikisyntaxhighlight lang="wikitext" inline>{{{1}}}{{{1}}}{{{1}}}</nowiki></codesyntaxhighlight> and <code><nowikisyntaxhighlight lang="wikitext" inline>{{t2}}</nowiki></codesyntaxhighlight> containing <code><nowikisyntaxhighlight lang="wikitext" inline>start-{{{1}}}-middle-{{{2}}}-end</nowiki></codesyntaxhighlight>:
*<code><nowikisyntaxhighlight lang="wikitext" inline>{{{a|b|c|d}}}</nowiki></codesyntaxhighlight> gives <code>{{{A|b|c|d}}}</code>
*<code><nowikisyntaxhighlight lang="wikitext" inline>{{{a|{{x3|b}}}}}</nowiki></codesyntaxhighlight> gives <code>{{{A|bbb}}}</code>
*<code><nowikisyntaxhighlight lang="wikitext" inline>{{{a|{{{b|c}}}}}}</nowiki></codesyntaxhighlight> gives <code>{{{A|{{{b|c}}}}}}</code>
*<code><nowikisyntaxhighlight lang="wikitext" inline>{{{a|[[b|c]]}}}</nowiki></codesyntaxhighlight> gives <code>{{{A|[[b|c]]}}}</code>
*<code><nowikisyntaxhighlight lang="wikitext" inline>{{{{{x3|a}}|b}}}</nowiki></codesyntaxhighlight> gives <code>{{{aaa|b}}}</code> - parameter aaa is undefined
*<code><nowikisyntaxhighlight lang="wikitext" inline>{{{{{{a|b}}}|c}}}</nowiki></codesyntaxhighlight> gives <code>{{{{{{A|b}}}|c}}}</code> - parameter b is undefined
 
*<code><nowikisyntaxhighlight lang="wikitext" inline>{{{a|<nowiki>b|c</nowiki><nowiki><</nowiki>/nowiki>}}}</codesyntaxhighlight> 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):
*:<code><nowikisyntaxhighlight lang="wikitext" inline>{{t2|{{{a|<nowiki>b|c</nowiki><nowiki><</nowiki>/nowiki>}}}}}</codesyntaxhighlight> gives <code>start-b|c-middle-{{{2}}}-end</code>
 
*<code><nowikisyntaxhighlight lang="wikitext" inline>{{{a|b{{!}}c}}}</nowiki></codesyntaxhighlight> 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:
----
<presyntaxhighlight lang="wikitext">{{fors/aux
|v@=
|c={{{call}}}
Line 83 ⟶ 84:
|pc4={{{pc4|=}}}|
1={{{1|@}}}|2={{{2|@}}}|3={{{3|@}}}
}}</presyntaxhighlight>
----
with {{Tim|fors/aux}}, containing:
----
<presyntaxhighlight lang="wikitext">{{{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}}}}}}}}</presyntaxhighlight>
----
 
In short form the latter consists of components
 
<codesyntaxhighlight lang="wikitext">[ v[''i''] | [s] <nowiki>{{[c]|[pc1]|[pc2]|[pc3]|[pc4]|[pv]=[''i'']}}</nowiki> ]</codesyntaxhighlight> (''i'' = 1, 2, 3, for ''i'' = 1 without [s])
 
or in terms of the parameters of the first template:
 
<codesyntaxhighlight lang="wikitext">[v[''i''|@] | [sep|] <nowiki>{{[call]|[pc1|]|[pc2|]|[pc3|]|[pc4|]|[pv|1]=[''i'']}}</nowiki> ]</codesyntaxhighlight>
 
This is indeed of the above-mentioned form <code>[a[b|c]|f([b])]</code>, with {{mono|1=a=v, b=''i'', c=@}}, and
 
<codesyntaxhighlight lang="wikitext">f(x) = [sep|] <nowiki>{{[call]|[pc1|]|[pc2|]|[pc3|]|[pc4|]|[pv|1]=x}}</nowiki></codesyntaxhighlight>
 
The assumptions mentioned above apply for d equal to null, and provided that no [''i''] is equal to "@".
 
===Variations===
Since {{code|1=v@=null}} we can also take make the concatenation the outer operation:
<codesyntaxhighlight lang="wikitext">[v[''i''|@] | [sep|]] [v[''i''|@] | <nowiki>{{[call]|[pc1|]|[pc2|]|[pc3|]|[pc4|]|[pv|1]=[''i'']}}</nowiki> ]</codesyntaxhighlight>
 
==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==