Difference between revisions of "Template:Ifnotempty"

From blackwiki
Jump to navigation Jump to search
imported>Patrick
(from m:)
 
imported>Primefac
m (Changed protection level for "Template:Ifnotempty": high-risk template with 4000+ transclusions ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)))
 
(5 intermediate revisions by 4 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>
<span style="font-size:150%">Documentation</span></div>}}
+
 
{{Documentation subpage}}
+
{{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| p | q }}</nowiki></code> gives "{{ifnotempty|x| p | q }}"
+
*<code><nowiki>{{ifnotempty| x | A | B }}</nowiki></code> gives "{{ifnotempty| x | A | B }}"
*<code><nowiki>{{ifnotempty|| p | q }}</nowiki></code> gives "{{ifnotempty|| p | q }}"
+
*<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| p | q }}</nowiki></code> gives "{{#if:x| p | q }}"
+
*<code><nowiki>{{#if:x| A | B }}</nowiki></code> gives "{{#if:x| A | B }}"
 +
*<code><nowiki>{{#if:| A | B }}</nowiki></code> gives "{{#if:| A | B }}"
  
 
==Internal technical details==
 
==Internal technical details==
For evaluating the condition the template uses the actual parser function; however, not directly with p and q, because this strips spaces and newlines from the result, but with index values 1 and 2. The result can be 1, 2. The template with the applicable name is called ([[Template:P1]] or [[Template:P2]]), with as parameters p and q.
+
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==
 
*[[Template:If]]
 
*[[Template:If]]
 
*[[m:Template:Ifnotempty]]
 
*[[m:Template:Ifnotempty]]
{{refs}}
 
  
[[[Category:If-then-else templates]]
+
[[Category:If-then-else templates]]
 +
 
 +
}}
 
</noinclude>
 
</noinclude>

Latest revision as of 16:29, 23 February 2018


50px Template documentation

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

  • {{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

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