Actions

Help

Difference between revisions of "Template"

From Sonic Retro

m (Parameters)
(Redirected page to cdn:Help:Template)
 
Line 1: Line 1:
'''← [[Help: Contents]]'''
+
#REDIRECT [[cdn:Help:Template]]
 
 
The MediaWiki software allows you to automatically substitute '''messages and templates''' in the article text.  As of the upgrade to MediaWiki 1.3 (in September 2004), templates now have their own [[Help:namespace|namespace]] inside the database.  Template pages will start with the ''Template:'' prefix.
 
 
 
==Include a message==
 
The syntax for insertion of the page "Template:name" is <nowiki>{{name}}</nowiki>.  This reference in the wikitext causes insertion of the template content when the referring page is rendered.
 
 
 
If the page "Template:name" does not exist, then <nowiki>{{name}}</nowiki> works as <nowiki>[[Template:name]]</nowiki>, a link to a non-existing page, leading to the edit page.
 
 
 
Self links do not give any complication: they are neatly displayed in bold type and not as links. However, templates should have the correct page names and not rely on redirecting, since the feature does not work in that case.
 
 
 
==Parameters==
 
You may also include a message as a '''template''' by applying parameters to the template.
 
 
 
Template parameters are either named or numbered. The syntax to add a message with parameters is <tt><nowiki>{{thing|param=value}}</nowiki></tt> with <tt><nowiki>{{{param}}}</nowiki></tt> tags in the template, or <tt><nowiki>{{thing|value1|value2}}</nowiki></tt> with <tt><nowiki>{{{1}}}</nowiki></tt>, <tt><nowiki>{{{2}}}</nowiki></tt>, etc. tags in the template. (Note that parameter tags in the template have ''three'' braces rather than two).
 
 
 
On rendering, surplus parameters are ignored. In the case of too few, the parameters will appear as links to nonexistent templates.
 
 
 
Parameter templates are used in the template <nowiki>{{cleanup-reason}}</nowiki>, for example. The template call
 
 
 
:<nowiki>{{cleanup-reason|Make this more [[Michael Jackson|awesome!]]}}</nowiki>
 
 
 
will produce the following note:
 
 
 
{{cleanup-reason|1=Make this more  [[Michael Jackson|awesome!]]|2=nocat}}
 
 
 
This example shows that you can even use wiki links in template parameters. This is not necessary if you are adding a well-formed URL - those are presented as links automatically.
 
 
 
==Substitutions==
 
If you include the string "subst:" after the double opening curly-braces, MediaWiki will ''substitute'' the template text in the wikitext rather than include it.  The net effect is that the current text of the template will be permanently saved, and will not be updated if and when the template is updated.
 
 
 
'''Example:''' <nowiki>{{subst:copyvio1}}</nowiki>
 
 
 
When subst is applied to a template, a variable in the template is copied as such in the wikitext.
 
 
 
You cannot substitute the same template more than five times per edit.  (However, this only applies to any one edit; you can then go back and add the same template five more times.  Why anyone might one to do this, though, is unclear.)
 
 
 
==Usage==
 
Templates are useful for any text for which one wants a copy in two or more pages, and there is no need for each copy to be edited independently, to adapt it to the page it is in. Since parameters can be used, versions may to that extent even be different, and parameter values can be edited independently for each.
 
 
 
'''See also:''' [[:Category:Sonic Retro Templates]]
 
 
 
[[Category:Help]]
 

Latest revision as of 17:22, 13 March 2018

Redirect to: