Template:If/Doc
From PCSAR
(Difference between revisions)
Brett Wuth (Talk | contribs)
(New page: {{Template doc|<nowiki>subst=subst:</nowiki>}} Based on http://meta.wikimedia.org/wiki/Template:If ==Usage== * 4 parameters: **<code><nowiki>{{if||x| p | q }}</nowiki></code> gives "{{if...)
Next diff →
Current revision
The template {{If|subst=subst:}}
Based on http://meta.wikimedia.org/wiki/Template:If
[edit] Usage
- 4 parameters:
{{if||x| p | q }}
gives " p "{{if||| p | q }}
gives " q "{{if|expr|2<3| p | q }}
gives " p "{{if|expr|2>3| p | q }}
gives " q "{{if|expr|2{{=}}3| p | q }}
gives " q "{{if|expr||2=2=3| p | q }}
gives " q "{{if|exist| Template:If | p | q }}
gives " p "{{if|exist| No Such:If | p | q }}
gives " q "{{if|error|<span class{{=}}"error">x</span>| p | q }}
gives " p "{{if|error| 7 | p | q }}
gives " q "{{if|error| 7 | p | }}
gives " "{{if|error| 7 | p |}}
gives ""{{if|error| 7 | p }}
gives " 7 "
- 5 parameters:
{{if|eq| u |u| p | q }}
gives " p "{{if|eq| u |v| p | q }}
gives " q "
Compare:
- 3 parameters:
{{#if:x| p | q }}
gives "p"{{#ifexpr:2<3| p | q }}
gives "p"{{#ifexist: Help:Link | p | q }}
gives "q"{{#iferror:<span class="error">x</span>| p | q }}
gives "p"{{#iferror: 7 | p | q }}
gives "q"{{#iferror: 7 | p | }}
gives ""{{#iferror: 7 | p |}}
gives ""{{#iferror: 7 | p }}
gives "7"
- 4 parameters:
{{#ifeq: u |u| 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.
Error messages (examples):
{{if|expr|1234>e3|1|0}}
gives Template:If: "#ifexpr:1234>e3" should give Expression error: Unexpected number but may not be evaluated due to the expansion depth limit.{{#ifexpr:1234>e3|1|0}}
gives Expression error: Unexpected number