Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Incubator escapee wiki:Template namespace
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!
{{short description|Type of page within Wikimedia}} <noinclude>{{pp-vand|small=yes}}{{pp-move-indef}}</noinclude> {{for|learning how templates work|Help:A quick guide to templates|Help:Template}} {{for|extended technical information|m:Help:Template|m:Help:Advanced templates}} :''This page not to be confused with [[Template:Namespaces]]'' {{Subcat guideline|project content guideline||WP:TMP|WP:NS10}} {{Nutshell| * The Template: namespace on Wikipedia contains templates created for consistent formatting, maintenance, and navigation. * Templates should not normally be used to store [[Wikipedia:What is an article?|article text]]. Such content belongs in the article pages themselves. }} {{Guideline list}} {{namespaces}} The '''Template namespace''' on Wikipedia is used to store [[Help:Template|templates]], which contain [[Help:Wiki markup|Wiki markup]] intended for inclusion on multiple pages, usually via [[Wikipedia:Transclusion|transclusion]]. Although the Template namespace is used for storing most templates, it is possible to transclude and substitute from other namespaces,<ref>Namespaces from which transclusion is not allowed are specified on a wiki by the variable [[mw:Manual:$wgNonincludableNamespaces|$wgNonincludableNamespaces]]</ref> and so some template pages are placed in other namespaces, such as the [[WP:User namespace|User namespace]]. Templates help maintain consistent formatting and aid navigation between articles. They often include optional and/or variable elements controlled by [[Help:Template#Parameters|parameters]] to allow for specialized use. Templates are also used to assist in a large variety of [[Wikipedia:Maintenance|Wikipedia maintenance]] tasks. Each template has a matching <code>Template talk:</code> page where editors can discuss the design and implementation of the associated template (see [[Help:Using talk pages]] for how to participate in talk page discussions). A template is transcluded into another page by including a template tag in that page's content. A template tag contains the template [[WP:page name|page name]] surrounded by double curly braces, e.g. {{tlc|Disambiguation}}. If the template's page name does not begin with a namespace and colon, it is assumed to be in the Template namespace. Internal links to template pages may be made by using the <code>Template:</code> prefix, e.g. <code><nowiki>[[Template:Disambiguation]]</nowiki></code>. See {{slink||Linking to templates}} for other ways to link to a template. == Guidelines == {{shortcut|WP:TG|WP:TMPG}} {{further|Wikipedia:Be bold#Template namespace}} * Templates should not normally be used to store [[Wikipedia:What is an article?|article text]], as this makes it more difficult to edit the content. They should also [[Wikipedia:Manual of Style#Scrolling lists and collapsible content|not be used to "collapse" or "hide" content]] from the reader. * Templates used in articles are designed to provide information to assist readers, such as navigation aids, formatting, or warnings that content is sub-standard. Templates that provide information only of service to editors should not appear on article pages{{snd}}use the article's talk page or other non-article namespaces. * Template function should be clear from the [[#Template names|template name]], but [[Wikipedia:Redirects#Template redirects|redirects]] can be created to assist everyday use of very popular templates. * [[Wikipedia:High-risk templates|High-risk templates]] should be semi-protected, [[Wikipedia:Template editor|template protected]], or fully protected as appropriate (see [[Wikipedia:Protection policy]]). This applies also to any high-use template redirects. * Templates should be clearly [[#Documentation|documented]] as to their usage and scope. * Templates should not be used to create lists of links to other articles when a [[Wikipedia:Categories, lists, and navigation templates#Categories|category]], [[Wikipedia:Categories, lists, and navigation templates#Lists|list page]], or [[Wikipedia:See also|"See also" section list]] can perform the same function. * Templates for short, temporary messages that will be removed quickly (such as on User_talk: pages) or that contain text which is not likely to ever be changed should be invoked with [[#Substitution|substitution]] (subst:). Typical templates that are intended for long-term use and are likely to require changes should be transcluded for easy future updates. * Templates that violate the guidelines on this page, have poorly defined function, are redundant, become orphaned or used on only one page, or violate any Wikipedia policies may be nominated for deletion at [[Wikipedia:Templates for discussion]]. == Linking to templates == Internal links to template pages may be made by using the <code>Template:</code> prefix or its [[WP:ALIAS|alias]] <code>TM:</code>, e.g. <code><nowiki>[[Template:Disambiguation]]</nowiki></code> or <code><nowiki>[[TM:Disambiguation]]</nowiki></code>. These links go to a page that directly contains a base template, but subpages such as the template's [[#Documentation|documentation]] can be linked directly as well, e.g. <code><nowiki>[[Template:Disambiguation/doc]]</nowiki></code>. To link to a template using a display format appropriate for templates, use [[Template:Tl]] (short for "template link"). For example, to reference the Cleanup template, typing <code><nowiki>{{tl|Cleanup}}</nowiki></code> results in {{tl|Cleanup}}. This does not call the template, but the display clearly indicates that the linked object is a template. You can also add parameters using [[Template:Tlp]]; for example, <code><nowiki>{{tlp|Convert|1|m}}</nowiki></code> displays as {{tlp|Convert|1|m}}. Check the template documentation on [[Template:Tl]] for other options, such as {{tlb|tlb}} (bold), {{tlx|tlx}} (code), {{tlxi|tlxi|param1|param2}} (italic parameters), {{tnl|tnl}} (no link), and many more. == Suggested practices == === Template names === {{shortcut|WP:TPN}} Template names should be made of one or more words, such as {{tlc|Train topics}}. The first character is not case-sensitive, so {{tlc|cleanup}} and {{tlc|Cleanup}} are the same template. All other characters are case sensitive, so {{tlc|cfd}} and {{tlc|cfD}} are not the same. Template names are easiest to remember if they follow standard English spelling, spacing, and capitalization (also see the [[Wikipedia:Naming conventions|naming conventions]] for articles). Avoid having templates whose names differ only in case, spacing, or punctuation. For templates with long names, [[Wikipedia:Redirect#Template_redirects|template redirects]] (often called shortcuts) can be created for ease of typing. For example, instead of typing {{tlc|Template link with subst}} the shortcut {{tlc|tls}} is available. === Sandbox for experiments === {{main|Wikipedia:Template sandbox and test cases}} If you wish to experiment with templates (and not have your experiments deleted before you are done with them), you may do so in the [[Template:Template sandbox|Template sandbox]]. You may also use the templates [[Template:X1|X1]], [[Template:X2|X2]], [[Template:X3|X3]], [[Template:X4|X4]], [[Template:X5|X5]], [[Template:X6|X6]], [[Template:X7|X7]], [[Template:X8|X8]], [[Template:X9|X9]], [[Template:X10|X10]], [[Template:X11|X11]], and [[Template:X12|X12]] for experimental purposes. To include a test template, use the form {{tlc|X1}} for template X1, {{tlc|X2}} for template X2, etc. Existing templates often each have their own [[Wikipedia:Template sandbox and test cases|sandbox and test case]] pages (especially those that use {{tl|Documentation}}). Changes should be thoroughly tested there before being applied to the main template, in order to prevent unintentional damage to many pages. === Readability of the code === For templates that have a large number of parameters, it can be helpful to place each parameter on a separate line and align the equals signs. This helps future editors to more easily read the wikicode. For example, if you wish to create a new [[Help:Infobox|infobox]] β which may contain dozens of parameters β your code might look like this: <pre>{{Infobox | header1 = Text of header1 | label2 = Text of label2 | data2 = Text of data2 | etc = etc }}</pre> Templates using many [[Help:Conditional expressions|conditional expressions]] often benefit from line spacing, such as the following code used in {{t|If either}} <syntaxhighlight lang=wikitext> {{#if:{{{1|}}} |{{{then|{{{3|}}}}}} |{{#if:{{{2|}}} |{{{then|{{{3|}}}}}} |{{{else|{{{4|}}}}}} }} }} </syntaxhighlight> While not necessary, the demonstrated linebreaks allow for easier parsing of which conditionals relate to which #if statement. === Line breaks === While line breaks in the body of a template code are useful for readability, line breaks at the beginning or end of template code could cause display issues on articles. Care should be taken when coding templates to ensure that there is no unnecessary whitespace. A single line break in an infobox may combine with a line break in an article to cause a paragraph break, or could cause an unwanted template in an inline template. As a general guideline, avoid two line breaks together in your template. These may "add up" with other line breaks in the article and be displayed as unwanted white space. For more information about line breaks as they affect wikitext, see [[Wikipedia:Line-break handling]]. To avoid unnecessary whitespace, ensure that any {{tag|noinclude|o}} tags are placed immediately after the template code. The following code is from {{t|questions}} and has good line break management. <syntaxhighlight lang=wikitext> {{notice|small=yes|If you want to ask a question, please see the [[Wikipedia:Questions]] page for guidance.}}<noinclude> [[Category:Wikipedia help templates]] </noinclude> </syntaxhighlight> === Substitution === {{main|Wikipedia:Substitution}} Invoking a template using the form : '''<code>{{<span style="color:red;">subst:</span>name of template ''(|parameters |...)''}}</code>''' (that is, inserting '''<code>subst:</code>''' immediately after the opening pair of curly brackets) will make a copy of the template text and place it on the page, where it will be viewable in the source. The template is no longer [[transclusion|transcluded]] and future changes to the template will not change the text. As a [[#Guideline|guideline]], this method should be used for any short, temporary messages which are removed quickly, such as on User_talk: pages. The standard new user {{tlx|Welcome}} message is a good example. Use subst: also if you need to edit the message after including it on the page. If you don't need to edit it, and would rather the message is automatically updated along with changes made to the template, don't use subst:. === Documentation === {{main|Wikipedia:Template documentation}} Because templates represent a step up in difficulty for the novice editor, documentation should be provided which describes its usage (optional parameters) and scope (where it should be used). There are two different ways to do this: One option is to use the {{t|documentation}} template to add a minor description directly onto the template page. As mentioned in {{slink||Line breaks}}, the first {{tag|noinclude|o}} tag should be placed on the same line as the last character of the actual template. For example: <syntaxhighlight lang=wikitext> '''This is a {{{1}}} article.'''<noinclude> {{documentation|content= Place this template on any article that requires description. It takes one parameter, an adjective used to describe the article. For example, {{article-describe|bad}} produces the text, '''This is a bad article.''' }} </noinclude> </syntaxhighlight> Another alternative is to create a formal [[Wikipedia:DOC|/doc subpage]] for the documentation (preferred for templates with multiple parameters, etc.). The {{t|documentation}} template is still called, but all of the displayed text will be transcluded from the template's /doc subpage. <syntaxhighlight lang=wikitext> '''This is a {{{1}}} article.'''<noinclude> {{documentation}} </noinclude> </syntaxhighlight> ===Modules=== {{main|Wikipedia:Lua}} Lua modules are sometimes used instead of templates to store reusable material. Reasons for this include usage of module-specific features such as [[loop (programming)|loops]] or stored values, and complex code is often easier to read and maintain in a module. If a module is easily implementable in a template it generally should be, since there are more users with experience editing templates. If a module is intended to be used in articles or talk pages, a template wrapper should generally be created to simplify usage without directly requiring the <code>#invoke</code> parser function. Documentation is then mostly located on the template's /doc page, with the module's documentation pointing to the template and/or explaining further technical details that are unnecessary at the primary template documentation. A template wrapper uses more of the [[WP:PEIS|post-expand include size limit]] than calling the module directly, therefore it may be necessary to avoid using one in articles that are near the limit. == History == Historically, an "msg:" prefix had to be added in front of the template name when it was used on a page. For example, <nowiki>{{msg:stub}} was typed instead of {{stub}}</nowiki>. This is no longer necessary. In Wikipedia's first 35 months, there was no template or transclusion mechanism at all. The page [[Wikipedia:Boilerplate text]] was created in September 2002 to collect frequently used text in various Wikipedia processes. The [[Help:MediaWiki namespace|MediaWiki namespace]] was introduced with MediaWiki 1.2.6 on December 6, 2003, and was used not only for the user interface but also for creating boilerplate text messages to be inserted in articles using the <nowiki>{{msg: ...}}</nowiki> syntax. This function was replaced with the [[Wikipedia:Template namespace|Template namespace]] during the software upgrade to MediaWiki 1.3 on May 30, 2004. As a function of the "[[User:Template namespace initialisation script|Template namespace initialisation script]]", all non-system messages were moved to the new namespace. The initialisation script also replaced MediaWiki: references in articles with Template: to bypass the redirects created by the moves. For a short time, [[Wikipedia:Articles for deletion]] (then known as ''votes for deletion'' or ''VfD'') used MediaWiki: messages named in the format "MediaWiki:VfD-''articlename''". These were moved to the Template: space in June 2004 and were named "Template:VfD-''articlename''". This usage is deprecated now in favor of subpages. Around 2005, growing complexity of template functions and the desire to consolidate similar templates led to the creation of extremely complex conditional hacks such as [[Wikipedia:Avoid using meta-templates|nested templates]] and [[Wikipedia:HiddenStructure|CSS tricks]]. These undesirable methods led to the development of [[m:Extension:ParserFunctions]], added in 2006 with MediaWiki 1.7. By 2009, many problems with template readability and complexity still remained (''[https://blog.wikimedia.org/2009/06/30/on-templates-and-programming-languages/ On templates and programming languages]''). In 2013, in order to address page load times, mostly due to slow template renders, [[Wikipedia:Lua|Lua]] was enabled, creating a Module: namespace for programmers to make use of (''[https://blog.wikimedia.org/2013/03/11/lua-templates-faster-more-flexible-pages/ New Lua templates bring faster, more flexible pages to your wiki]''). == Searching for templates == Use this form to search in the Template: or Template_talk: namespaces. See [[Help:Searching]] for more information. <inputbox> type=search break=no namespaces=Template**,Template_talk searchbuttonlabel=Search within the Template: namespace </inputbox> Pages which contain information on commonly used templates: * [[Wikipedia:Template index]] for an index of text-based templates. * [[Wikipedia:Navigation template]]s for a partial list of various subject-class navigational elements. * [[Wikipedia:List of infoboxes]] for infoboxes, which are small panels that summarize key features of the page's subject. * [[Wikipedia:Categorization]] for templates used for [[Help:Category|categories]] * [[Wikipedia:Citation templates]] for templates used to format article [[Wikipedia:Citing sources|references and citations]] If you're unable to find an existing template for your situation, but don't feel comfortable creating one yourself, you can ask for help at [[Wikipedia:Requested templates]]. ==See also== * [[Help:Template]] for information on developing templates and syntax details * [[Help:Magic words]] for all template modifiers * [[Help:Conditional tables]] * [[Wikipedia:Template standardisation]] ==Notes== {{Reflist}} {{Wikipedia policies and guidelines}} {{Wikipedia templates|state=collapsed}} [[Category:Wikipedia template administration|Namespace]] [[Category:Wikipedia how-to|{{PAGENAME}}]] [[Category:Wikipedia features|{{PAGENAME}}]] [[Category:Wikipedia template guidelines|namespace]] [[Category:Wikipedia template help]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Documentation
(
edit
)
Template:For
(
edit
)
Template:Further
(
edit
)
Template:Guideline list
(
edit
)
Template:Main
(
edit
)
Template:Namespaces
(
edit
)
Template:Notice
(
edit
)
Template:Nutshell
(
edit
)
Template:Pp-move-indef
(
edit
)
Template:Pp-vand
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Shortcut
(
edit
)
Template:Slink
(
edit
)
Template:Snd
(
edit
)
Template:Subcat guideline
(
edit
)
Template:T
(
edit
)
Template:Tag
(
edit
)
Template:Template link
(
edit
)
Template:Tl
(
edit
)
Template:Tlb
(
edit
)
Template:Tlc
(
edit
)
Template:Tlp
(
edit
)
Template:Tlx
(
edit
)
Template:Tlxi
(
edit
)
Template:Tnl
(
edit
)
Template:Wikipedia policies and guidelines
(
edit
)
Template:Wikipedia templates
(
edit
)