ਫਰਮਾ:If{{ safesubst:p{{ safesubst:#if{{{1}}}:{{{2}}}|1|2}}|{{{3}}}|}}
With this template the parser functions of the ParserFunctions collection with names starting with "#if" can be used in a way such that they do not strip spaces and newlines from the "then" and "else" part. Spaces still do not affect the outcome of the condition. Parameter 1 selects the if-type as "eq", "expr", "exist" or "error" (for #iferror), or empty "||" for a simple if-there (for #if). The template can be repeatedly nested 6 or 7 levels, one inside the other, because the outer-most is completed before running either the then/else inner levels. 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/>". UsageWhere p is output for a true statement and q is output for a false statement.
Compare:
For example, with a template named Template:Template name containing the code 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 "}}". IndentationIf 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:
When the else-clause is indented to the next line, a newline (CR/LF) is added:
To indent the else-clause, split an HTML-form comment, as " Performance considerationsBecause Template:If must prepare the parameters for Using P-if syntax: A similar if-structure can be coded without Template:If, by using the
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.
See also
|
Portal di Ensiklopedia Dunia