Toggle search
Search
Toggle menu
notifications
Toggle personal menu
Editing
Template:If/doc
(section)
Template page
Views
Read
Edit source
View history
associated-pages
Template
Discussion
More actions
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Usage== '''Where p is output for a true statement and q is output for a false statement.''' *<syntaxhighlight lang="text" inline>{{if||x| p | q }}</syntaxhighlight> gives "{{if||x| p | q }}". Notice the empty first parameter, seen as two adjacent vertical bars. *<syntaxhighlight lang="text" inline>{{if|expr|2<3| p | q }}</syntaxhighlight> gives " p " *<syntaxhighlight lang="text" inline>{{if|eq| u |u| p | q }}</syntaxhighlight> gives "{{if|eq| u |u| p | q }}" *<syntaxhighlight lang="text" inline>{{if|exist| Help:Link | p | q }}</syntaxhighlight> gives "{{if|exist| Help:Link | p | q }}" *<syntaxhighlight lang="text" inline>{{if|error|{{#expr:x}}| p | q }}</syntaxhighlight> gives "{{if|error|{{#expr:x}}| p | q }}" Compare: *<syntaxhighlight lang="text" inline>{{#if:x| p | q }}</syntaxhighlight> gives "{{#if:x| p | q }}" *<syntaxhighlight lang="text" inline>{{#ifexpr:2<3| p | q }}</syntaxhighlight> gives "{{#ifexpr:2<3| p | q }}" *<syntaxhighlight lang="text" inline>{{#ifeq: u |u| p | q }}</syntaxhighlight> gives "{{#ifeq: u |u| p | q }}" *<syntaxhighlight lang="text" inline>{{#ifexist: Help:Link | p | q }}</syntaxhighlight> gives "{{#ifexist: Help:Link | p | q }}" *<syntaxhighlight lang="text" inline>{{#iferror:{{#expr:x}}| p | q }}</syntaxhighlight> gives "{{#iferror:{{#expr:x}}| p | q }}" For example, with a template named ''Template:Template name'' containing the code <syntaxhighlight lang="text" inline>{{#ifeq: {{{parameter}}} |u| p | q }}</syntaxhighlight>, entering the code <syntaxhighlight lang="text" inline>{{Template name|parameter=u}}</syntaxhighlight> into an article gives "p", but <syntaxhighlight lang="text" inline>{{Template name|parameter=v}}</syntaxhighlight> gives "q". The text of either the then-clause or else-clause is only processed and expanded when triggered. Hence, any templates in use are only expanded once the then-clause or else-clause is matched, otherwise they are skipped as merely paired braces, "{{" with "}}". ===Indentation=== If indenting the markup, care must be taken to avoid extra newlines when indenting "}}" on the next line. An extra bar pipe "|" can be added after the else-clause to complete that text, and allow "}}" to then be placed anywhere without adding a newline into the else-clause. For example: :::* <syntaxhighlight lang="text">{{if|{{{1|}}} |then found parameter 1|else no parameter 1| β extra "|" ends else-clause }}</syntaxhighlight > When the else-clause is indented to the next line, a newline (CR/LF) is added: :::* <syntaxhighlight lang="text">{{if|{{{1|}}} |then found parameter 1 β extra newline here |else noparameter 1| }}</syntaxhighlight> To indent the else-clause, split an [[HTML]]-form comment, as "<code><!--</code>" with next line as "<code>-->|else...</code>". Unless each then-clause and else-clause is carefully tested, to watch for extra newlines, then the results are likely to cause broken lines, with extra line breaks for each newline. For that reason, a global edit with simple search-and-replace of "<code>{#if:</code>" to "<code>{if||</code>" is likely to leave newline problems, wherever the original markup was wrapped to indent either the else-clause or "}}" of each if-structure. Indenting the then-clause is not a problem.
Summary:
Please note that all contributions to Turing Complete are considered to be released under the Creative Commons Attribution-ShareAlike (see
TuringComplete:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)