Help:Templates: Difference between revisions

Jump to navigation Jump to search
→‎Learn more: Transclusion & substitution section
(colourcoding for visual & source editors; small language changes)
(→‎Learn more: Transclusion & substitution section)
Line 49: Line 49:
{{LCARS-bar-heading|Learn more|COLOR={{Color|blue}}}}
{{LCARS-bar-heading|Learn more|COLOR={{Color|blue}}}}
{{UC|section=yes}}
{{UC|section=yes}}
=== Transclusion and substitution ===
As described above, adding a template to a page using a template call (such as <code><nowiki>{{Mirror universe}}</nowiki></code>) is called ''transclusion''. Each time the page is opened, the current form of the template is displayed.
Sometimes, it is more desirable that the display doesn’t change but is static. The code may be copy-pasted, but this might break it. For example, the inclusion tags (see below) should be removed by the user by hand. Instead of copy-pasting, ''substitution'' should be used. When the page is saved, substitution replaces the template call with the template code as it would appear had the template merely been transcluded.
For example, if [[Template:Mirror universe]] is substituted to a page, the template call would be replaced by the following code:<br>
<nowiki>:''This article pertains to a subject of the [[Mirror universe]].''[[File:Mirror-universe.jpg|x40px|link=Category:Mirror universe]]<br clear=all></nowiki>
Now, should the template be edited, the display on the page won’t change. Note that the code of the template in its template page has a line <code><nowiki><noinclude>[[Category:Mirror universe]]</noinclude></nowiki></code>. Since this line is not included in the transclusion, it won’t be in the substitution either.
<div style="padding: 5px 10px 5px; border-left: 5px solid lightpink;">In source editing, substitution is executed with word <code>subst:</code> in the template call, e.g. <code><nowiki>{{subst:Mirror universe}}</nowiki></code></div>
Many templates call other templates, magic words or parser functions. Substituting a template will only transclude calls in its code. In order to substitute all templates, magic words and parser functions, safe substitution may be used.
<div style="padding: 5px 10px 5px; border-left: 5px solid lightpink;">In source editing, safe substitution is executed with word <code>safesubst:</code> in the template call, e.g. <code><nowiki>{{safesubst:Mirror universe}}</nowiki></code></div>
Note that substitution and safe substitution will increase the lenght of the wikicode on page considerably and might make difficult to edit. Some templates are designed so that they are dynamic, so safe substitution in particular may defeat the purpose.
The wikicode of a template may also be called.
<div style="padding: 5px 10px 5px; border-left: 5px solid lightpink;">In source editing, wikicode call is executed with word <code>msgnw:</code> in the template call, e.g. <code><nowiki>{{msgnw:Mirror universe}}</nowiki></code></div>


=== More on the topic ===
=== More on the topic ===
Line 57: Line 76:
* [https://www.mediawiki.org/wiki/Help:Templates Templates], MediaWiki help page about templates
* [https://www.mediawiki.org/wiki/Help:Templates Templates], MediaWiki help page about templates
* [https://en.wikipedia.org/wiki/Help:Template Template], Wikipedia help page about templates
* [https://en.wikipedia.org/wiki/Help:Template Template], Wikipedia help page about templates
* [https://www.mediawiki.org/wiki/Help:Substitution Substitution], MediaWiki help page about substitution
{{End Columns}}
{{End Columns}}


[[Category:Help]]
[[Category:Help]]
1,769

edits

Navigation menu