Template:Ifnotempty: Difference between revisions

Template page
m (8 revisions imported: Imported from https://en.wikipedia.org/w/)
 
(6 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<includeonly>{{{{{|safesubst:}}}{{{{{|safesubst:}}}#if:{{{1}}}|p1|p2}}|{{{2}}}|{{{3|}}}}}</includeonly><noinclude><div class="template-documentation" style="margin-top:1em;">{{#if:defaultnotblank|<div style="padding-bottom:3px; border-bottom:1px solid #aaa; margin-bottom:1ex;">
<includeonly>{{ {{{|safesubst:}}}{{ {{{|safesubst:}}}#if:{{{1}}}|p1|p2}}|{{{2}}}|{{{3|}}}}}</includeonly><noinclude>{{Documentation}}
<span style="font-size:150%">Documentation</span></div>}}
{{Documentation subpage}}
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.
 
==Usage==
*<code><nowiki>{{ifnotempty|x| p | q }}</nowiki></code> gives "{{ifnotempty|x| p | q }}"
*<code><nowiki>{{ifnotempty|| p | q }}</nowiki></code> gives "{{ifnotempty|| p | q }}"
Compare:
*<code><nowiki>{{#if:x| p | q }}</nowiki></code> gives "{{#if:x| p | q }}"
 
==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 p and q. This produces either p or q, without trimming.
 
==See also==
*[[Template:If]]
*[[m:Template:Ifnotempty]]
{{refs}}
 
[[[Category:If-then-else templates]]
</noinclude>
</noinclude>

Latest revision as of 10:54, 17 November 2023