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!
== Making templates behave differently when transcluded or substituted == Sometimes it is desirable to make a template behave differently when substituted rather than when transcluded. A common trick for doing this is to use an expression like <code><nowiki>{{{{{subst|subst:}}}ns:0}}</nowiki></code>. This evaluates to the empty string if the template is being substituted (since the inner substitution takes effect, giving the prefix of [[WP:namespace|namespace]] 0, which is empty), but to "<nowiki>{{subst:ns:0}}</nowiki>" if the template is being transcluded (since substitution cannot take place after transclusion). A common application is in templates which are designed only to be substituted, to make them produce a warning if they are mistakenly transcluded instead. This is done in templates like {{tl|prod}}, which are designed to produce a timestamp (e.g. for adding pages to dated categories), and will not be able to do this if transcluded. A template, {{tl|issubst}}, has been created to simplify this. It returns "yes" if substitution is being performed, or the empty string otherwise. This can then be used as the parameter of a conditional parser function to make the template display a warning method if it is being transcluded, or to otherwise change the behaviour of a template depending on whether it is being transcluded or substituted.
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