FANDOM


Substitution is automatic conversion of wikitext of a page referring to a template, variable, or parser function when the referring page is saved.

In the case of template substitution the template call is replaced by the template content with substitution of the parameters. Thus a template is used as macro and the page is macro expanded when the page is saved rather than, as usually happens, when the page is viewed.

In the case of substitution of a variable or parser function the reference to it is replaced by the resulting value.

Substitution is done by putting the modifier subst: after the double opening braces.

The result (in the form of the difference with the saved wikitext) can be seen before (or without) saving by pressing "Show changes". However, if the text covers more than one paragraph this diff page is not very suitable for copying the result (e.g. for stepwise substitution without saving every step), because of plus signs in the margin.

ApplicationsEdit

Substitution of a template:

  • Make a rendered page independent of the template:
    • The rendered page does not change when the template is edited.
    • The page can be copied to another project without copying the template.
  • Make page rendering easier and therefore faster for the server.
  • Analyse and demonstrate the working of templates. However, in some cases substitution works differently.
  • Make the correspondence between wikitext and rendered page easier to understand (this may apply, the opposite may also apply).

Substitution of a time-dependent variable:

  • Make a rendered page independent of the time.

Substitution of a page-dependent variable:

  • Make a rendered page independent of renaming of the page and of copying the wikitext to another page (the opposite applies if the variable PAGENAME is used in a no-include part of the page to include the page itself).

Some MediaWiki extensions have the restriction that if they are used in a template with parameters, they only work if the template is substituted. This applies for example in the case of a template parameter inside an in-page query in MediaWiki.


Parser functionsEdit

If <includeonly> is used in conjunction with substitution, the entire template must be substituted. The example below would be used to generate a time stamp at the time of writing.

{{<includeonly>subst:</includeonly>CURRENTDAY}} {{<includeonly>subst:</includeonly>CURRENTMONTHNAME}} {{<includeonly>subst:</includeonly>CURRENTYEAR}}, {{<includeonly>subst:</includeonly>CURRENTTIME}}

Wikipedia_small_logo_rounded.png

This page uses Creative Commons licensed content from Wikipedia (view authors).

Template substitution is an alternate way to embed information contained in a template. Substitution is performed by placing the code subst: between the template braces, before the template name, like this:
{{subst:Templatename}}

Process

Normally, when the code for a template named {{something}} is added to a page, it will still say {{something}} in the wikitext when you next edit the page.

Non subst template

A template in the editor that has not been substituted.

However, if you substitute a template, the text {{subst:something}} will be replaced with the full template code from Template:Something when you save the page. If you edit the page again, you will no longer see {{subst:something}} in the text:

Subst template

The same template after being substituted.

Reasons for substituting

Most templates should not be substituted in pages, as doing so will make their contents harder to edit once added to a page. However, there are some instances where it can be useful.

In some cases, templates that exist solely to provide formatting or quick links should be substituted rather than included normally. For example, if a template exists to create the full format link to a game page, as a shorthand for editors to type, it is better to substitute the template. Adding templates for small uses such as links can unnecessarily add to the max template count of a page for a minor function that can be replicated in wikitext.

In other cases, it may be that a template code is designed to be edited manually after it has been placed on a page. In these cases, substituting the template code, and immediately editing the page after, is ideal.

For talk page messages, preserving the code of the template used at the time is often best, as it can be odd to have someone's talk page change long after they have seen the notice. This includes welcome templates, as well as signatures.

Additionally, it is possible to use template substituting to remove a template from pages. Simply clear out the contents of the template on the template page, and substitute it on all pages that included it, to remove it and any of its content.

See also

Further help and feedback

Community content is available under CC-BY-SA unless otherwise noted.