(Move documentation onto its own page from Template:Ifnotempty) |
m (4 revisions imported: Imported from https://en.wikipedia.org/w/) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 15: | Line 15: | ||
==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 A and B. This produces either A or B, without trimming. | 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. The template's code is a substitution-safe version of | ||
<syntaxhighlight lang="wikitext"> | |||
{{ {{#if: {{{1}}} | P1 | P2 }} |{{{2}}}|{{{3}}}}} | |||
</syntaxhighlight> | |||
==See also== | ==See also== |
Latest revision as of 10:54, 17 November 2023
{{#invoke:Message box|mbox}}Template:High-use
With this template #if can be used in a way such that it does not 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[edit source]
{{ifnotempty| x | A | B }}
gives " A "{{ifnotempty|x| A | B }}
gives " A "{{ifnotempty| | A | B }}
gives " B "{{ifnotempty|| A | B }}
gives " B "
Compare:
{{#if:x| A | B }}
gives "A"{{#if:| A | B }}
gives "B"
Internal technical details[edit source]
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. The template's code is a substitution-safe version of
{{ {{#if: {{{1}}} | P1 | P2 }} |{{{2}}}|{{{3}}}}}
See also[edit source]