Template:If/doc: Difference between revisions
| [checked revision] | [checked revision] |
Content deleted Content added
Caleb Cooper (talk | contribs) Created page with "{{stack|{{Documentation subpage}}{{high-risk}}}}{{Commons Import}} With this template the parser functions of the mw:Help:Extension:ParserFunctions|..." |
Caleb Cooper (talk | contribs) No edit summary |
||
Line 1:
{{stack|{{Documentation subpage}}{{high-risk}}}}{{Commons Import}}
With this template the [[Wikipedia:Help:parser function|parser functions]] of the [[
This template can be substituted, when the expression or comparison will not change. Functionally, a lead-space character is stored, internally, as a simple blank character. Note, in many cases a null nowiki tag ("<nowiki/>") could be used, without [[Template:If]], to allow a lead-space (such as "<nowiki/> xx") anywhere, but the internal storage puts a 43-character marker for "<nowiki/>" in string length. However, there is no extra expansion depth for a nowiki-tag, such as in trailing space, "zz <nowiki/>".
Line 35:
|else noparameter 1|
}}</syntaxhighlight>
To indent the else-clause, split an [[Wikipedia:HTML|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.
==Performance considerations==
Because [[Template:If]] must prepare the parameters for <code>#if, #ifeq, #ifexpr,</code> (etc.) there is a slight overhead when using it. It has been timed to run at speeds of 290 instances per second, so 29 uses would take only 0.1 s, a tenth of a second to run, to make 29 comparisons. Each nested use adds 5 levels to the template expansion depth, so 7 nested if-templates would use 35 levels (5*7) of the [[
'''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:
Line 49:
==See also==
*[[Template:Ifnotempty]] - for simplicity and to reduce the limitations due to the expansion depth limit, this is a separate template corresponding to #if only.
*[[Template:Switch]], for a default result
*[[Wikipedia:Help:Conditional expressions|Help:Conditional expressions]]
<includeonly>{{Sandbox other||
[[Category:If-then-else templates]]
| |||