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!
==Performance considerations== Because [[Template:If]] must prepare the parameters for <code>#if, #ifeq, #ifexpr,</code> (etc.) there is a slight overhead when using it. Each nested use adds 5 levels to the template expansion depth, so 7 nested if-templates would use 35 levels (5*7) of the [[m:Help:Expansion_depth|41-level limit]]. '''Using P-if syntax:''' A similar if-structure can be coded without '''Template:If''', by using the {{tlx|P1}} and {{tlx|P2}} templates in a "P-if" structure. [[Template:P1]] always returns parameter 1, and P2 returns the 2nd. So, a comparison of 4 versus 3 can be coded using P-if syntax form: :: Example of <code>#ifexpr</code>: <syntaxhighlight lang="text" inline>"{{P{{#ifexpr: 4 > 3|1|2}}| then 4 greater| else 4 lower}}"</syntaxhighlight> :: Result for <code>#ifexpr</code>: "{{P{{#ifexpr: 4 > 3|1|2}}| then 4 greater| else 4 lower}}" ← ''the comparison invoked'' {<nowiki/>{P1}}. The expansion depth of a P-if is only 4 levels deep, but nesting of the then-clause or else-clause might be more confusing than using nested levels of Template:if. :: Example of <code>#if</code>: <syntaxhighlight lang="text" inline>"{{P{{#if:{{{2|x}}}|1|2}}| then {2} set| else {2} empty}}"</syntaxhighlight> :: Result for <code>#if</code>: "{{P{{#if:{{{2|}}}|1|2}}| then {2} set| else {2} empty}}" ← ''the comparison invoked'' {<nowiki/>{P2}}.
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)