Wikipedia:Substitution

Substitution is the one-time, permanent copying of content onto a Wikipedia page. It differs from transclusion, which continually updates as the parent template changes. Substitution is most often used to handle templates, and this page lists templates that should either always or never be substituted.

Definition

Ordinarily, templates will be transcluded, which means that their content is always retrieved directly from the most recent version of the template. This is advantageous because, if the template's page is changed, every other page that uses that template will display the updated content. In this case, when someone is editing a page that transcludes a template, they only see the {{Template call}} and not the underlying code. This procedure is used for most templates to avoid having to manually keep pages up-to-date individually.

However, some templates can also be substituted. Substitution is basically a fancy "copy and paste" when it's used. In practice, once an editor substitutes a template on a page and publishes their edit, the entire content of the template at the moment it is substituted will be inserted into the page, along with any parameters passed to it, as if the editor had manually copied the code and pasted it. Since the substituted content is now an integral part of the page, it can be modified without affecting other pages or the parent template itself. This means that, if the template is changed in the future, the pages in which it has already been substituted will not be affected in any way, because there is no longer a connection between them and the substituted template.

Usage

To transclude a template, its name is simply enclosed in double curly braces, as in: {{Please ping}}. To substitute a template instead, the string subst: is added after the opening braces, as in {{subst:Please ping}}. The contents of {{Please ping}} will then be inserted ("expanded") in the location where the template call is placed in the page. Before saving, you can check the resulting wikitext, which differs from what you see in the editor, by clicking "Show changes".

Benefits

Neutral

Drawbacks

Documenting substitution

Usage of a template through subst: does not automatically show up in page histories. Therefore, it is strongly suggested that the template be mentioned in the edit summary so other editors can easily understand your edits. (For instance, include "Substituted [[Template:Please ping]]" or "{{subst:Please ping}}".) If you don't, they might think you wrote the entire template code yourself.

HTML comments outside noinclude tags are included in the substituted wikitext, so a comment can be used to mention the template, and then find it again later. See any of the user warning templates, which all use this approach. Template {{uw-coi}}, for example, places the comment onto the page where it is substituted, thus enabling searching for that comment as a proxy for searching for substitutions of the template. The § Notes section of the template's documentation provides a search link based on this technique.

If you are creating or editing templates that are commonly substituted, you can add a hidden comment to the template so that other editors know which templates were substituted (e.g. <!-- Template:Please ping -->). Use {{subst:HTML comment}} if you want to write HTML comments that contain wikitext expansions.

Substitution of parameters does not work inside comments, but a workaround for this is to begin an intended comment with <!<noinclude />-- so that it turns into a comment once transcluded.

Template-specific usage

This page also lists templates that should either always or never be substituted except in the Wikipedia namespace. Bots that do such replacements will never be used on the original template. If you are going to use a bot to substitute templates, please read through the talk page first, as many are under dispute or change status over time, and substitution is permanent.

Templates that must be substituted

These templates have a purpose and/or syntax that requires them to be substituted.

Templates that should always be substituted

This is a list of templates that should always be substituted. Each list is ordered alphabetically with grouped series. This is not a comprehensive list; other less-used templates may also need to be substituted. See the template's documentation for details.

Templates that should not be substituted

Technically, templates should not be substituted if they:

  1. contain calls to ParserFunctions (#if, #switch, etc.), unless, where possible, these are substituted too (see mw:Help:Substitution#Multilevel substitution)
  2. leave some parameters to their defaults by not specifying them, unless the alternative default mechanism is used
  3. contain external links, as the formatting of the URL to perform queries or look-ups may change

This is because these constructs are not replaced in the generated wiki-code (single level substituting of case (A) leaves the #if or #switch constructs verbatim at the subst location and (B) leaves constructs like {{{1|default value}}}).

If specific consensus is to eliminate a particular call of such a template, Special:ExpandTemplates can be used to expand that call to plain wiki-syntax.

List

This is a list of templates that should not be substituted. This is because they contain formatting standard code, complex code, or code that breaks if substituted.

  • Various citation/reference templates which contain very complex conditional code (see: WP:CITET).
  • Infobox templates, various ones for the sake of bot-identification and consistency.
  • {{Javadoc:EE}}, {{Javadoc:SE}}, {{Javadoc:SE-guide}}, conditional templates whose purpose is to update the links when the master template is updated.
  • {{ISP}}, {{Openproxy}}, {{repeat vandal}}, {{SharedIP}}, {{SharedIPEDU}}, {{s/wnote}}, not messages to the users (so it is no problem if they change from their original form), so no reason to subst, but the standard reasons not to subst apply.
  • {{ln}}, {{lnt}}, complex code
  • {{Main}}, maintains formatting standard.
  • {{switch}}, also conditional templates; substituting breaks usage
  • {{See also}}, standard formatting for see also list
  • {{selfref}}, does not work when substituted, as it is meant to contain different code in mirrors.
  • {{Signpost-subscription}}, must be updated weekly.
  • {{stub}} templates, various ones for simplified usage and removal
  • {{talkarchive}}, {{archive}}
  • {{tl}}, {{tlp}}, {{ttl}}, {{ti}}, {{tic}}, {{tls}}, {{cl}}, {{ccl}}, many very widely used, {{tl}} with over 7,620,000 transclusions at last count. Quicker to type than their substitutions, and non-substituting them allows new Wikipedians to learn about them and be able to use them.
  • {{sockpuppet}} and similar templates are intended to be placed on the top-level page in user space. (Note: warnings and notices in the user talk space should be substituted.)
  • {{lowercase}}, {{correct title}} add a comment about why an article is misnamed.

Most templates related to renaming or deleting pages are used temporarily, and thus do not need to be substituted (it just makes more work to delete them).

Under debate

See also

Sister-projects

Templates for substitution

Notes

  1. ↑ While templates are substituted the most often, magic words, variables, parser functions, and most Wikipedia pages can also be substituted. For a technical overview, see Help:Substitution.