Help:Templates: Difference between revisions
PhantomCaleb (talk | contribs) |
Rayolinels (talk | contribs) m (→Transclusion and substitution: Clearing up what appears to have been a tiny typo/mixup. Generally templates should not be transcluded? No, rather generally they should not be substituted...) |
||
Line 34: | Line 34: | ||
{{Small|In reality, [[Template:MM]] outputs something quite different when substituted, but this illustrates the point.}} | {{Small|In reality, [[Template:MM]] outputs something quite different when substituted, but this illustrates the point.}} | ||
Generally, templates should be | Generally, templates should be transcluded and not substituted. Substitution does not preserve a reference to the template—it's like you didn't use a template at all. You lose the ability to have the content update automatically when you change the template. | ||
==Making Templates== | ==Making Templates== | ||
For information on how to ''make'' templates, see [[Zelda Wiki:Making Templates]]. | For information on how to ''make'' templates, see [[Zelda Wiki:Making Templates]]. |
Latest revision as of 01:41, 19 December 2022
Zelda Wiki's Help Guide |
Basic Editing: Getting Started Canon Policy Archiving Talk Pages |
- See also: Help:Templates on MediaWiki
A template is a page made to be included in other pages. They standardize content or formats that need to be repeated on many pages, by encapsulating them in a separate page in the Template
namespace. They can abstract away complicated syntax, namely parser functions.
Templates are most often used by transclusion. That is, by enclosing the name of the template page in {{double curly brackets}}
. When placed in another page, the entire contents of that template page will be displayed where you placed it. Templates can have parameters that modify their appearance or content.
An example of a common template is an infobox, such as Template:Infobox Item. Infobox templates appear in the upper right corner of nearly every article on the wiki. There are many other types of templates.
Using Templates
Parameters
Templates can have anonymous parameters, named parameters, or both. With anonymous parameters, order matters.
Template:Color is a template with anonymous parameters. It is used like this: {{Color|TWWHD Vermilion|merchant's oath}}
, which produces merchant's oath. You wouldn't get the right output if you changed the order of the parameters.
Template:Clarify is a template with both anonymous and named parameters. It is used like this: {{Clarify|BotW|reason= Some text here}}
. There's one anonymous parameter for the game, and a named reason
parameter for the display text.
Transclusion and substitution
Templates can be used by transclusion or by substitution. When you transclude a template on a page and save it, the source will still show {{<Template name>}}
when you go back to edit it. Conversely, when you substitute a template, the actual contents of the template gets copied and saved to the page.
Input | Output view | Output source |
---|---|---|
{{MM}} |
Majora's Mask | {{MM}}
|
{{subst:MM}} |
Majora's Mask | ''[[The Legend of Zelda: Majora's Mask|Majora's Mask]]''
|
In reality, Template:MM outputs something quite different when substituted, but this illustrates the point.
Generally, templates should be transcluded and not substituted. Substitution does not preserve a reference to the template—it's like you didn't use a template at all. You lose the ability to have the content update automatically when you change the template.
Making Templates
For information on how to make templates, see Zelda Wiki:Making Templates.