Template:Ifnotempty

From TrainzOnline
Revision as of 23:37, 5 July 2013 by Fabartus (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
{{#if:defaultnotblank|
Documentation
}}
This is a documentation subpage for Template:Ifnotempty.

 
It contains usage information, categories and other informational content that is best arranged so that it is not part of the original template page, such as in many cases, examples of how to use the template in question.
  • Documentation subpages were developed to reduce server demands, or to protect the code version of widely used templates.
     

With this template #if can be used in a way such that it does not strip spaces and newlines from the "then" and "else" part. For evaluating the condition spaces and newlines are stripped like with ParserFunctions.

Contents

Usage

  • {{ifnotempty|x| p | q }} gives "{{safesubst:{{safesubst:#if:x|p1|p2}}| p | q }}"
  • {{ifnotempty|| p | q }} gives "{{safesubst:{{safesubst:#if:|p1|p2}}| p | q }}"

Compare:

  • {{#if:x| p | q }} gives "{{#if:x| p | q }}"

Note that, unlike parser functions, templates require writing equals signs in values of unnamed parameters as {{=}}

For full substitution, simply use subst:

This page has it's origination in the Wikimedia Foundation's development website Meta-wiki or has been exported and is now part of the newer Mediawiki software resources website for assisting new wikis with startup organization and has been copied according to the terms of the (CC-BY-SA-3.0), the GFDL standard GNU pulic license or the source file(s) is/are in the public domain.
or safesubst:
This page has it's origination in the Wikimedia Foundation's development website Meta-wiki or has been exported and is now part of the newer Mediawiki software resources website for assisting new wikis with startup organization and has been copied according to the terms of the (CC-BY-SA-3.0), the GFDL standard GNU pulic license or the source file(s) is/are in the public domain.

. If the condition contains a parser function, template, or variable, that should be substituted too. Optionally the "then" or "else" part can also be substituted.

Expansion depth limit

13 levels allowed:

{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|a}}}}}}}}}}}}}}}}}}}}}}}}}} gives {{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|a|}}|}}|}}|}}|}}|}}|}}|}}|}}|}}|}}|}}|}}

{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|{{ifnotempty|x|a}}}}}}}}}}}}}}}}}}}}}}}}}}}} gives {{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|{{safesubst:{{safesubst:#if:x|p1|p2}}|a|}}|}}|}}|}}|}}|}}|}}|}}|}}|}}|}}|}}|}}|}}

Internal technical details

For evaluating the condition the template uses the actual parser function; however, not directly with p and q, because this strips spaces and newlines from the result, but with index values 1 and 2. The result can be 1, 2. The template with the applicable name is called (Template:P1 or Template:P2), with as parameters p and q.

Conditions

#if:

Condition: string not empty.

See also

1 | references-column-count references-column-count-{{{1}}} }} }} }}" {{#if: | style="-moz-column-width:{{{colwidth}}}; column-width:{{{colwidth}}};" | {{#if: | style="-moz-column-count:{{{1}}}; column-count:{{{1}}};" }} }}> Unknown extension tag "references"
<div style="clear:both;" />
This page has it's origination in the Wikimedia Foundation's development website Meta-wiki or has been exported and is now part of the newer Mediawiki software resources website for assisting new wikis with startup organization and has been copied according to the terms of the (CC-BY-SA-3.0), the GFDL standard GNU pulic license or the source file(s) is/are in the public domain.
Personal tools