m (→See also) |
(unsubst documentation template, and add edge cases to usage) |
||
Line 1: | Line 1: | ||
<includeonly>{{{{{|safesubst:}}}{{{{{|safesubst:}}}#if:{{{1}}}|p1|p2}}|{{{2}}}|{{{3|}}}}}</includeonly><noinclude> | <includeonly>{{ {{{|safesubst:}}}{{ {{{|safesubst:}}}#if:{{{1}}}|p1|p2}}|{{{2}}}|{{{3|}}}}}</includeonly><noinclude> | ||
{{Documentation|content= | |||
With this template [[mw:Help:Extension:ParserFunctions|#if]] can be used in a way such that it does not [[m:Help:Newlines_and_spaces#Stripping_on_expansion|strip spaces and newlines]] from the "then" and "else" part. For evaluating the condition spaces and newlines are stripped like with ParserFunctions. | With this template [[mw:Help:Extension:ParserFunctions|#if]] can be used in a way such that it does not [[m:Help:Newlines_and_spaces#Stripping_on_expansion|strip spaces and newlines]] from the "then" and "else" part. For evaluating the condition spaces and newlines are stripped like with ParserFunctions. | ||
This template can be substituted. | |||
==Usage== | ==Usage== | ||
*<code><nowiki>{{ifnotempty|x| | *<code><nowiki>{{ifnotempty| x | A | B }}</nowiki></code> gives "{{ifnotempty| x | A | B }}" | ||
*<code><nowiki>{{ifnotempty|| | *<code><nowiki>{{ifnotempty|x| A | B }}</nowiki></code> gives "{{ifnotempty|x| A | B }}" | ||
*<code><nowiki>{{ifnotempty| | A | B }}</nowiki></code> gives "{{ifnotempty| | A | B }}" | |||
*<code><nowiki>{{ifnotempty|| A | B }}</nowiki></code> gives "{{ifnotempty|| A | B }}" | |||
Compare: | Compare: | ||
*<code><nowiki>{{#if:x| | *<code><nowiki>{{#if:x| A | B }}</nowiki></code> gives "{{#if:x| A | B }}" | ||
==Internal technical details== | ==Internal technical details== | ||
For evaluating the condition (determining non-emptiness of the first parameter) the template uses parser function #if, producing 1 if the condition is true, and 2 otherwise. The template with name equal to "P" followed by the index value produced (hence [[Template:P1]] or [[Template:P2]]), is called with as parameters | For evaluating the condition (determining non-emptiness of the first parameter) the template uses parser function #if, producing 1 if the condition is true, and 2 otherwise. The template with name equal to "P" followed by the index value produced (hence [[Template:P1]] or [[Template:P2]]), is called with as parameters A and B. This produces either A or B, without trimming. | ||
==See also== | ==See also== | ||
Line 18: | Line 23: | ||
[[Category:If-then-else templates]] | [[Category:If-then-else templates]] | ||
}} | |||
</noinclude> | </noinclude> |
Revision as of 13:16, 1 March 2012
This page has been transcluded from Template:Ifnotempty/Documentation.