Wikipedia:Template substitution

(Redirected from Wikipedia:Subst)

The "subst:" keyword (short for "substitution") is used as a prefix inside template code. It changes the way the software expands the template. Ordinarily, a template will be expanded "on the fly"; that is, every time you edit a page where the template is used, the template calls a separate page for the text, and the text it shows is updated. Placing "subst:" inside the template code when using it on a page, tells the software to substitute the template with text of the template (that is, the text that is on the template's article page when the template is added to the page), so the output of the template is saved when you save the page, and it does not change even if the template is edited.

You can subst a template by adding subst: to the beginning of the template tag. For example, you can use {{subst:test5}} instead of {{test5}}.

When this is an important part of an edit, it is very good to mention the template in the edit summary (for instance, put "{{subst:test}}" or "test1 applied" in your edit summary so other editors can easily see what you have done).

Benefits of substitution

change
  • Templates are often edited or deleted. When adding a template to a page, ask yourself if you want it to change as the template is edited. If your answer is "no", substitute the template you use.
    An example of this is the {{welcome}} template. The archives of a user's talk page should show the actual welcome message they received, not the current welcome message.
  • If there is a template you would like to edit for one page, but you don't want to modify the template for all the pages that use it, and you don't want to make a new template, you can substitute the template; then you can make the modifications with a second edit.
    For example: a template might be used with all the states in the United States and the District of Columbia. For an article about the District of Columbia the template may need to use different words. For this purpose, you can substitute the template and then fix the wording on the article about the District of Columbia.
  • Substitution of frequently-used protected templates can be used to avoid damage caused by template vandalism.
  • People can learn more complex wikicode by looking at the output of a substituted template. Using the same template without substitution does not show the template code to them.

Drawbacks of substitution

change
  • When a template is substituted, the result is no longer linked to the template, so it will be hard to find all pages displaying that text. This problem can be solved by adding a link to the template in the template's code, or by using categories.
  • Substitution increases the size of articles.
  • A substituted template can add a lot of wiki-code or HTML to the article. This way, people who do not have enough skills may find it harder to edit the page.
  • Substituting templates prevents newcomers from learning to use templates.
  • If the template is just being used temporarily, it is usually better not to substitute. Substituted templates are much harder to remove or edit.
  • When a vandalised template is substituted, it is more difficult to repair because it will not fix when the vandalised template is fixed.

Further reading

change