Difference between revisions of "Template:Ifnotempty"

From EVE RP Wiki
Jump to: navigation, search
rp>Patrick
m (7 revisions imported)
 
(7 intermediate revisions by 3 users not shown)
Line 2: Line 2:
 
<span style="font-size:150%">Documentation</span></div>}}
 
<span style="font-size:150%">Documentation</span></div>}}
 
{{Documentation subpage}}
 
{{Documentation subpage}}
With this template [[mw:Help:Extension:ParserFunctions|#if]] can be used in a way such that it does not [[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 [[Help:Newlines_and_spaces#Trimming_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==
 
==Usage==
Line 14: Line 14:
  
 
==Expansion depth limit==
 
==Expansion depth limit==
7 levels allowed:
+
13 levels allowed:
  
<code><nowiki>{{if||x|{{if||x|{{if||x|{{if||x|{{if||x|{{if||x|{{if||x|a}}}}}}}}}}}}}}</nowiki></code> gives {{if||x|{{if||x|{{if||x|{{if||x|{{if||x|{{if||x|{{if||x|a}}}}}}}}}}}}}}
+
<code><nowiki>{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|a}}}}}}}}}}}}}}}}}}}}}}}}}}</nowiki></code> gives {{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|a}}}}}}}}}}}}}}}}}}}}}}}}}}
  
<code><nowiki>{{if||x|{{if||x|{{if||x|{{if||x|{{if||x|{{if||x|{{if||x|{{if||x|a}}}}}}}}}}}}}}}}</nowiki></code> gives {{if||x|{{if||x|{{if||x|{{if||x|{{if||x|{{if||x|{{if||x|{{if||x|a}}}}}}}}}}}}}}}}
+
<code><nowiki>{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|a}}}}}}}}}}}}}}}}}}}}}}}}}}}}</nowiki></code> gives {{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|a}}}}}}}}}}}}}}}}}}}}}}}}}}}}
 
 
<code><nowiki>{{if||||{{if||||{{if||||{{if||||{{if||||{{if||||{{if||||a}}}}}}}}}}}}}}</nowiki></code> gives {{if||||{{if||||{{if||||{{if||||{{if||||{{if||||{{if||||a}}}}}}}}}}}}}}
 
 
 
<code><nowiki>{{if||||{{if||||{{if||||{{if||||{{if||||{{if||||{{if||||{{if||||a}}}}}}}}}}}}}}}}</nowiki></code> gives {{if||||{{if||||{{if||||{{if||||{{if||||{{if||||{{if||||{{if||||a}}}}}}}}}}}}}}}}
 
 
 
<code><nowiki>{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|a}}}}}}}}}}}}}}</nowiki></code> gives {{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|a}}}}}}}}}}}}}}
 
 
 
<code><nowiki>{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|a}}}}}}}}}}}}}}}}</nowiki></code> gives {{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|{{if|expr|1|a}}}}}}}}}}}}}}}}
 
 
 
To allow more levels there is a separate [[Template:Ifexpr]].
 
  
 
==Internal technical details==
 
==Internal technical details==
For evaluating the condition the template uses the actual parser functions; however, not directly with p and q, because this strips spaces and newlines from them, but with index values 1 and 2. The result can be 1, 2, or, only in the case of #ifexpr, an error message. Using a switch these are converted to p1, p2, and if/errmsg, respectively. The template with the applicable name is called ([[Template:P1]], [[Template:P2]], or [[Template:If/errmsg]]), with as parameters p, q, and {{{2}}}. Templates p1 and p2 ignore {{{2}}}; template if/errmsg is only called in the case of #ifexpr, in the case of a wrong expression {{{2}}}; it ignores p and q and uses {{{2}}} for display in the error message.
+
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.
  
 
==Conditions==
 
==Conditions==
Line 42: Line 32:
 
{{refs}}
 
{{refs}}
  
<div style="clear:both;" /></div></div></noinclude>
+
<div style="clear:both;"></div></div></div>[[Category:Branching templates]]</noinclude>

Latest revision as of 19:48, 30 April 2021

Documentation

Script error: No such module "Template translation". 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.

Usage

  • {{ifnotempty|x| p | q }} gives " p "
  • {{ifnotempty|| p | q }} gives " q "

Compare:

  • {{#if:x| p | q }} gives "p"

Note that, unlike parser functions, templates require writing equals signs in values of unnamed parameters as {{=}}

For full substitution, simply use Template:Cnw or Template:Cnw. If the condition contains a parser function, template, or variable, that should be substituted too. Optionally the "then" or "else" part can also be substituted.

Expansion depth limit

13 levels allowed:

{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|a}}}}}}}}}}}}}}}}}}}}}}}}}} gives {{Expansion depth limit exceeded|x|{{Expansion depth limit exceeded|x|{{Expansion depth limit exceeded|x|a}}}}}}

{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|a}}}}}}}}}}}}}}}}}}}}}}}}}}}} gives {{Expansion depth limit exceeded|x|{{Expansion depth limit exceeded|x|{{Expansion depth limit exceeded|x|{{Expansion depth limit exceeded|x|a}}}}}}}}

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.

Conditions

#if:

Condition: string not empty.

See also