Community Central
Community Central

Template substitution is an alternate way to embed information contained in a template. Information embedded this way is independent of any future changes to the 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.

Notes[]

  • You may use the Source editor preview function to see what the page will look like without actually performing the substitution.
  • Substitution leaves no evidence that the embedded content originally came from a template. You may add an HTML comment like <!--Template:Foo--> to the template to alert future editors of this.
  • Substitution works on magic words like {{PAGENAME}}.
  • Substitution works on parser functions but substitution occurs before transclusion. If template {{Hotkey}} returns an empty string, then {{subst:#if:{{Hotkey}}|yes|no}} will produce "yes" when the page is saved because the transclusion of Hotkey has not happened yet and "{{Hotkey}}" is a non-empty string. Typing {{subst:#if:{{subst:Hotkey}}|yes|no}} will produce the expected result of "no" as the inner substitution is performed first.
  • Depending on the application, substituting templates that call other templates may require recursive substitution, which is beyond the scope of this page. See Recursive substituion on Wikipedia.

Reasons for substituting[]

Most templates should not be substituted in pages, as doing so will make their contents more complicated 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, similar to preload templates. In these cases, substituting the template code, and immediately editing the page afterwards, 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 templates used to welcome users, as well as signatures.

Additionally, it is possible to use template substitution 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[]