Template:Ifeq

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

A conditional template, for testing if two strings match. The first two arguments must be simple names appropriate for named parameters of a template, or empty. If they differ, then this ends up using Template:Use with the indirect argument named only once, so the overall expansion is the original fourth argument. But if they match, then this ends up calling the {{Use}} template with the indirect argument named twice, so the overall expansion is the second use of the indirect name, or the original third argument.

That is, this is an alternate implementation of {{#ifeq:test1|test2|if equal|if differ}}, with a slightly different syntax:
{{ifeq|test1|test2|if equal|if differ}}

Examples:

{{ifeq|{{{1|none}}}|none|[[{{{1}}}]]}}

results in parameter 1 converted to a link, unless it is blank or the literal text "none" in which case nothing is output

{{ifeq|{{{NAMESPACE}}}|User|[[:Category:blah]]|[[Category:blah]]}}

links to the category page without belonging to the category if in the User namespace, otherwise tags the page with a category