Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help
Community portal
Encyc
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Help:Substitution
(section)
Help page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Technical implementation== Substitution is part of the process performed on saving a page, and causes the wikitext saved as a result of the edit to differ from the text which the user actually entered in the edit window. Other replacements performed during this process include expansion of links using the [[WP:pipe trick|pipe trick]], and replacement of multiple tildes with signatures and timestamps. This means that substitution necessarily occurs before any actions performed at the time of page rendering (conversion of the stored wikitext to HTML). In particular, ''substitutions are done before transclusions''. So typing <code><nowiki>{{subst:Help:L{{in(tut)}}k}}</nowiki></code> will not do substitution, even though {{tl|in(tut)}} returns the text "in" and [[Help:Link]] exists. The transclusion of {{tl|in(tut)}} has not yet taken place when the substitution is attempted. However, replace <code><nowiki>{{in(tut)}}</nowiki></code> with <code><nowiki>{{subst:in(tut)}}</nowiki></code>, and both substitutions will be performed in the expected order. Similarly: *Typing <code><nowiki>{{subst:#if:{{x0}}|yes|no}}</nowiki></code> gives the wikitext "yes", even though {{tl|x0}} is an empty template, since the conditional parameter evaluates to the non-empty string "<nowiki>{{x0}}</nowiki>". However <code><nowiki>{{subst:#if:{{subst:x0}}|yes|no}}</nowiki></code> produces "no", since the inner substitution is performed first. *Typing <code><nowiki>{{subst:#expr:2*{{{p|3}}}}}</nowiki></code> returns ''Expression error: unrecognised punctuation character "{"'', as the undefined parameter <nowiki>{{{p}}}</nowiki> has not been replaced by its default value (3) when the substitution occurs. *If {{tl|t6}} contains the text "t2|a", then <code><nowiki>{{ {{subst:t6}} }}</nowiki></code> will produce the wikitext "<nowiki>{{ t2|a }}</nowiki>", rendered as "{{t2|a}}" Contrast this with the behaviour of <code><nowiki>{{ {{t6}} }}</nowiki></code>, which is rendered as "{{ {{t6}} }}", because the parser does not reinterpret the pipe as a separator during the non-substituted expansion stage. (Similarly, <code><nowiki>{{subst:{{subst:t6}} }}</nowiki></code> gives the wikitext <code><nowiki>{{subst:t2|a }}</nowiki></code>, which only on the next edit will be substituted with {{t2|a}}.) Clicking the "Show changes" button during editing shows the wikitext that will result ''after'' substitution and other immediate replacements are carried out. Clicking "Show preview" shows what the rendered page will look like after these replacements. 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 <code>subst:</code> 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. Note also that if instances of the <code>subst:</code> syntax appear in a template that is being ''transcluded'', then they will be rendered unchanged (as "<nowiki>{{subst:...}}</nowiki>"), since no substitution in wikitext is possible at the rendering stage. This feature can be exploited to control template behaviour (see [[#Making templates behave differently when transcluded or substituted|Β§ Making templates behave differently when transcluded or substituted]]). However, it may be inconvenient when a template is designed to be possible to transclude as well as substitute – in this case <code>safesubst:</code> can be used instead of <code>subst:</code> (see [[#safesubst|Β§ The safesubst: modifier]]). ==={{anchor|safesubst}}The safesubst: modifier=== {{shortcut|WP:SAFESUBST}} The <code>subst:</code> modifier can be replaced by the alternative modifier <code>safesubst:</code>. The two have the same behaviour, except when they are encountered during non-substituted expansion (transclusion or direct viewing) of a template. In such a situation, the code <code><nowiki>{{subst:...}}</nowiki></code> remains unparsed<!-- is this blank or as plaintext? -->, whereas the <code><nowiki>{{safesubst:...}}</nowiki></code> is treated as if no modifier were present – and so the subtemplate is transcluded or the variable or parser function evaluated. Hence the <code>safesubst:</code> modifier is used in the code of templates which are designed to produce recursive substitution when substituted; but that are also intended to work when transcluded or simply to be viewed directly. Contrasted with using the <code>subst:</code> modifier, such templates would break in such cases 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|Β§ Recursive substitution]].
Summary:
Please note that all contributions to Encyc are considered to be released under the Creative Commons Attribution-Share Alike License (see
Encyc:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
This page is a member of a hidden category:
Category:Pages with short description
Toggle limited content width