We've Moved! Just as Gamepedia has joined forces with Fandom, this wiki had joined forces with our Fandom equivalent. The wiki has been archived and we ask that readers and editors move to the now combined wiki on Fandom. Click to go to the new wiki.

Template:If

From The Vault - Fallout Wiki
Jump to: navigation, search
Template documentation (for the template shown above, sometimes hidden or invisible)

With this template the parser functions of Extension:ParserFunctions with names starting with #if (those, apart from #switch, with the functionality of a conditional expression) can be used in a way such that they do not strip spaces and newlines from the "then" and "else" part. For evaluating the condition spaces and newlines are stripped like with ParserFunctions.

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 " p "
    • {{if|exist| Help:Links | p | q }} gives " p "
    • {{if|exist| Hulp:Links | 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:Links | p | q }} gives "p"
    • {{#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 subst: or safesubst:. 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.

Technical

Copyright.pngThe contents of this page were entirely or partially copied from Wikipedia, the Free Encyclopedia, and are therefore licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. The original version, its history and authors can be found at the Wikipedia page "Template:If".
Documentation transcluded from Template:If/doc.