*** Welcome to piglix ***

Help:Substitution


Variables and parser functions can also be substituted, meaning that their current value will be recorded permanently on the page – they will not be re-evaluated whenever someone views the page.

Generally speaking, templates are transcluded rather than substituted, although there are some that are specifically designed to be substituted (and may not work if transcluded). Some reasons for substituting templates include:

Disadvantages of substitution may include:

For more detailed guidance, including lists of templates which should or should not be substituted, see .

To substitute a template, use the same syntax as for transclusion, but include subst: after the opening double braces. For example, to substitute the template {{}}, type {{subst:afd}}. Parameters can be included as in the case of transclusion, for example {{subst:afd|Some article}}.

Use the same syntax to substitute variables and parser functions, e.g. {{subst:PAGENAME}} or {{subst:#switch:{{NUMBEROFADMINS}}|1=Foo|1000=Car|#default=Baz}}.

There may be whitespace between the opening braces and the "subst:". However it is recommended not to have any space or newlines immediately after the "subst:", as this will not work in every case.

Similarly:

If a page substitutes itself (e.g. in the noinclude part of a template page) it substitutes the old version, as it was before the current edit.

If the expansion of a substituted template itself contains instances of the subst: syntax, then the substitutions are performed recursively. However substitution is not automatically recursive – if a substituted template contains ordinary transclusions or variables and parser functions which are not explicitly substituted, then these will not be substituted.

The subst: modifier can be replaced by the alternative modifier safesubst:. The two have the same behaviour, except when they are encountered during non-substituted expansion (transclusion or direct viewing) of a template. In this situation, the code {{subst:...}} remains unparsed, whereas {{safesubst:...}} is treated as if no modifier were present (so the subtemplate is transcluded or the variable or parser function evaluated).

Hence the safesubst: modifier is used in the code of templates which are designed to produce recursive substitution when substituted, but are also intended to work when transcluded – or simply to be viewed directly. Using plain subst: in such templates would break in the case of transclusion (and possibly on direct viewing). For details on how to implement this (in particular, how to prevent the substitution from being performed as soon as the template code is saved), see § Recursive substitution.


...
Wikipedia

...