Help:A quick guide to templates: Difference between revisions

Content deleted Content added
Copied from meta, last edited February 2008
...
 
(156 intermediate revisions by more than 100 users not shown)
Line 1:
{{Short description|Wikimedia project page or help page}}
{{H:h|editor toc}}
{{pp-semi-indef|small=yes}}
{{pp-move-indef|small=yes}}
{{Wikipedia how to|H:TQG|sort-by=Templates, A quick guide to}}{{Wiki markup}}
This is a quick '''overview of templates'''. Full details can be found in [[Help:Template]] and [[mw:Manual:Advanced templates]].
 
A '''template''' is a Wikipedia page created to be included in other pages. It usually contains repetitive material that may need to show up on multiple articles or pages, often with customizable input. Templates sometimes use [[MediaWiki]] parser functions, nicknamed "[[Help:Magic words|magic words]]", a simple [[scripting language]].
This is a quick '''overview of templates'''. Full details can be found in '''[[Help:Template]]''' and '''[[Help:Advanced templates]]'''.
 
TemplatesTemplate pages are pagesfound in the template [[HelpWikipedia:NamespaceTemplate namespace|template namespace]]. This means any page beginningwhose title begins with "Template:", such as <nowiki>"[[Template:Templatenamefoo]]</nowiki>", can be used asfor athat templatepurpose. The content offrom a template titled Template:foo can be added tointo a Wikipedia page by editing a page and typing <code><nowiki>{{templatenamefoo}}</nowiki></code> into it. When then viewing the page, <code><nowiki>{{foo}}</nowiki></code> is automatically replaced by the content of the page "Template:foo". If the page "Template:foo" is later altered, all the pages with <code><nowiki>{{foo}}</nowiki></code> in them will change automatically.
 
TemplatesAmong other things, templates are used to add recurring messages to pages in a consistent way, to add [[Wikipedia:Glossary#Boilerplate text|boilerplate]] messages, and to create navigational boxes and to provide cross-language portability of texts.
 
When a template is automatically expanded and appears on a page, it is said to be "[[Wikipedia:Transclusion|transcluded]]".
==Creating, editing and using templates==
You start a new template in the same way you would [[Help:Starting a new page|start a normal page]]. The only difference is that its title must start with <tt>Template:</tt>.
 
[[Wikipedia:Template documentation|Templates are documented]] (or should be) at their pages. Thus if you want to know how to use a template whose name is "foo" (perhaps because you've seen <code><nowiki>{{foo|...}}</nowiki></code> in the source of an article), then go to "Template:foo". (The documentation itself will usually be located at "Template:foo/doc", but is also transcluded onto the "Template:foo" main page.)
Once you have made the template, you can add <nowiki>{{</nowiki>''templatename''<nowiki>}}</nowiki> to the pages you want to use it on. Every page using this template will get the same boilerplate text, each time a user visits it. When the template is updated, all pages containing the template tag will be automatically updated.
 
==Creating, editing, and using templates==
Alternatively, you can add <nowiki>{{</nowiki>subst:''templatename''<nowiki>}}</nowiki> to the pages you want to use the boilerplate text on. The system will fetch a one-time copy of the template text and '''substitute''' it into the page, in place of the template tag. If anyone edits the template afterwards, pages that used the <tt>subst:</tt> keyword will '''not be updated'''. Sometimes that's what you want.
You can start a new template in the same way that you would [[Wikipedia:Starting an article|start an article page]]. The only difference is that its title must start with <code>Template:</code>.
 
Once you have made the template—for example ''Template:foo''—you can add <code><nowiki>{{</nowiki>''foo''<nowiki>}}</nowiki></code> to the pages that you want to use it on. Every page using this template uses the same [[boilerplate (text)|boilerplate]] text each time that a user visits it. When the template is updated, all pages containing the template tag are automatically updated.
If the template you want to edit looks like <nowiki>{{foo}}</nowiki>, you would go to [[Template:foo]] to edit it. To get there, type in the URL to your address bar, [[Help:Searching|search]] for it, or make a link in the [[{{ns:4}}:sandbox|sandbox]] and click on it.
 
Alternatively, if you do not wish the page to reflect future updates to the template, you can add <code><nowiki>{{</nowiki>subst:''foo''<nowiki>}}</nowiki></code> to the pages on which you want to use the boilerplate text. The system fetches a one-time copy of the template text and '''[[Wikipedia:Substitution|substitutes]]''' it into the page in place of the template tag. If anyone edits the template afterwards, pages that used the <code>subst:</code> keyword do '''not update'''. Sometimes that is what you want.
Once you are there, just click "edit" or "edit this page" and edit it in the same way you would any other page. You can add anything you would add to a normal page, including text, images and other templates. Please be aware that your edit might affect many pages, so be cautious.
 
If the template that you want to edit looks like <code><nowiki>{{foo}}</nowiki></code>, you would go to Template:foo to edit it. To get there, type "Template:foo" in the search box (see [[Help:Searching|search]]), or make a wikilink like <code><nowiki>[[Template:foo]]</nowiki></code> somewhere, such as in the [[{{ns:4}}:sandbox|sandbox]], and click on it.
 
Once you are there, just click "edit" or "edit this page" at the very top of the page (not the documentation edit button lower down) and edit it in the same way that you would any other page. You can add anything that you would add to a normal page, including text, images, and other templates. When editing templates that are in use, it is a good idea to do so in a sandbox, as described in the [[Wikipedia:template sandbox and test cases|template sandbox and test cases]] how-to guide.
 
===Parameters===
Templates can have parameters which the page can dynamically incorporate into the transcluded page. Instead of just the template name, like <code><nowiki>{{foo}}</nowiki></code>, an embedded template tag would have additional values separated by [[vertical bar]]s (|), e.g. <code><nowiki>{{foo|July|lc=yes}}</nowiki></code>. Here <code>July</code> is the value of the first unnamed parameter; <code>yes</code> is the value of the named parameter <code>lc</code>. Writing the template page for a template with parameters is more complicated than for a template with no parameters. See [[Help:Template]].
 
===Editing existing templates===
When you edit a template that is in use, it can affect many pages throughout Wikipedia all at once.
 
{{slink|Wikipedia:Template editor|Use}} has tips to help avoid problems.
 
== Template link template==
To include the actual full name of the template as text (including the surrounding braces) in a Wikipedia article, apply the [[template:template link|'''template link''' template]]. The primary motivation to do this is in instruction and documentation. A short example is the code:
 
::<code><nowiki>{{tl|foo}}</nowiki></code>
:generates
::{{tl|foo}}
 
==FAQ==
; How can I find out how to use an existing template?
;Can I use a template in more than one project? : No, if you want to use it on two different language Wikipedias, for example, you would need to create it twice.
: To see the documentation for the template whose name is "foo", go to "Template:foo".
; Are templates case sensitive? : Yes, except usually the first letter.
 
; Can I add parameters? : Yes, see [[Help:Template]] for instructions.
; How do I find out where a template is used?
; How many templates can I use in a page? : As many as you like (in older versions you could not use the ''same one'' more than 5 times).
: To list all pages onto which a template is transcluded, use '''[[Special:WhatLinksHere]]''' and type in template:''templatename'' ([[Help:What links here|more info]]).
; I edited the template, so why didn't the page it is used on change? : There are some caching bugs. One way to force refresh is to do '''edit''' on the page in which the template appears, and to then click on '''Save page''' without having changed anything - there is no need to fill in the ''Summary'' field since there will not be any ''history'' of this as a change generated. Alternatively, refreshing by pressing Ctrl and F5 often helps. Another way is add "&action=purge" to the address, like you would for "&action=edit" (e.g, :index.php?title=foo&action=purge).
 
; Can I move a template to a new name? : Yes, this works in exactly the same way as normal [[Help:Renaming (moving) a page|page moves]]. When a page called for inclusion is a redirect page, the redirect target is included instead.
; Can I use a template in more than one project?
; Can I use a template within a template? : You can use a template tag within template content, but not within a template tag: in the latter case the parser will prematurely end the original template tag when it reaches the first pair of curly closing braces....
: No, if you want to use it on two different language Wikipedias, for example, you would need to create it twice.
;How do I add a new template?: You start a new template in the same way you would start a normal page. The only difference is that its title must start with Template:.
 
; Where is the manual for the programming language used to write templates?: The language inside templates is the same language as regular wiki markup, but template writers tend to use the more complex available functions such as #if: statements. See [[m:help:ParserFunctions|ParserFunctions]] and see the other "advanced functioning" help pages listed below.
; Are template names case-sensitive?
: Yes, except usually (on most wikis)<sup>[[meta:Help:Template#Case sensitivity|[1]]]</sup> the first letter.
 
; How can I add parameters?
: See [[Help:Template]] for instructions.
 
; I edited the template, so why didn't the page it is used on change?
: Wikipedia and your computer both store webpage ''[[Web cache|caches]]''&nbsp;– or saved copies&nbsp;– and don't always show you an updated page. First, try to [[WP:BYPASS|bypass your browser's cache]] by pressing {{key press|Opt|Cmd|R}}, {{key press|Ctrl|Shift|R}}, or {{key press|Ctrl|F5}}. If that fails, you may need to [[WP:PURGE|purge]] the page's cache (which can be done several different ways). Perhaps the easiest way to do this is by clicking '''edit''' on the page in which the template appears, and then clicking on '''Publish changes''' without having changed anything&nbsp;– there is no need to fill in the ''Summary'' field since there will not be any ''history'' of this as a change generated.
 
; Can I move a template to a new name?
: Yes, this works in exactly the same way as normal [[Help:Moving a page|page moves]]. When a page called for inclusion is a redirect page, the redirect target is included instead.
 
; Can I use a template within a template?
: Yes.
 
; How do I add a new template?
: You start a new template in the same way you would start a normal page. The only difference is that its title must start with {{code|Template:}}. Don't forget to document it so that other editors can use it!
 
; Where is the manual for the programming language used to write templates?
: The language inside templates is the same language as regular wiki markup, but template writers tend to use the more complex available functions such as #if: statements. See Wikipedia's [[Help:Template]] and Wikimedia's [[mw:Help:Template]], including all of "advanced functioning" help pages listed toward the bottom of [[mw:Help:Template#Links to other help pages|that page]].
 
==Examples==
*[[w:en:Template:stub]]: an often used message (at English Wikipedia).
<!-- *[[w:en:Template:europe]]: a navigational template -->
*[[w:en:Template:Biological classification]]: a template with parameters (at English Wikipedia).
*[[b:en:Template:GeneralChemTOC]]: a horizontal menu bar (at English [[Wikibooks]]).
*[[w:en:Template:Underwater work]]: a template as a simple table with a picture (at English Wikipedia).
 
== Wikipedia-specific help ==
*[[Help:Template]] (more details)
*[[m:Help:Templates]] (details from [[Wikimedia]])
*[[mw:Manual:Advanced templates]] (advanced details from Wikimedia)
*[[Wikipedia:Template namespace]] (the usual [[Wikipedia:Namespace|namespace]] for templates)
*[[Wikipedia:Transclusion]] (transcluding templates)
*[[Wikipedia:Substitution]] (substituting templates)
*[[Wikipedia:Template messages]] (categorised list of links to available templates)
 
{{Help navigation}}
{{Wikipedia technical help|collapsed}}
 
{{DEFAULTSORT:Quick guide to templates, A}}
*[[w:en:Template:stub]]: an often used message
*[[w:en:Template:europe]]: a navigational template
*[[w:cy:Template:Dosbarthiad_biolegol]]: a template with parameters
*[[w:en:Template:Familia]] and [[fr:Modèle:Familia]]: cross-language templates
*[[eo:Ŝablono:El]]: a small, often used image
*[[b:en:Template:GeneralChemTOC]]: a horizontal menu bar
{{h:f|enname=A quick guide to templates}}