Template:If

From MHWiki
Revision as of 13:22, 25 October 2011 by Ericb (talk | contribs) (Graduate to main template namespace from User:Ericb/If)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A conditional template, for testing if text is empty. The first argument cannot start with "=". If the first argument contains any text, then this ends up calling the Template:Use template with two arguments, one named "use" with the original second argument as its value, and the other will have an unrelated name, so the overall expansion is the one use of the name "use" - the second argument. But if the first argument is empty (or missing), then this ends up using the {{Use}} template with use= specified twice, and the last use wins, giving the overall expansion of the third argument.

That is, this template is an alternative implementation of {{#if:test|if text|if empty}}, with a slightly different syntax:
{{if|test|if text|if empty}}

Examples:

{{if|{{{1|}}}|[[{{{1}}}]]|none}}

results in either parameter 1 converted to a link, or the literal text "none"

{{if|{{{NAMESPACE}}}|[[Category:blah]]}}

tags a page with a category, but only if the page is in the main namespace