Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Wikipedia:Template namespace

Page semi-protected
From Wikipedia, the free encyclopedia
Type of page within Wikimedia

For learning how templates work, seeHelp:A quick guide to templates andHelp:Template.
For extended technical information, seem:Help:Template andm:Help:Advanced templates.
This page not to be confused withTemplate:Namespaces
Blue tickThis page documents an English Wikipediaproject content guideline.
Editors should generally follow it, thoughexceptions may apply.Substantive edits to this page should reflectconsensus. When in doubt, discuss first onthis guideline's talk page.
This page in a nutshell:
  • The Template: namespace on Wikipedia contains templates created for consistent formatting, maintenance, and navigation.
  • Templates should not normally be used to storearticle text. Such content belongs in the article pages themselves.
Wikipedia guidelines
Behavioral
Discussions
Content
Editing
Categorization
Style
Deletion
Project content
Other
Search


Namespaces
Subject namespacesTalk namespaces
0(Main/Article)Talk1
2UserUser talk3
4WikipediaWikipedia talk5
6FileFile talk7
8MediaWikiMediaWiki talk9
10TemplateTemplate talk11
12HelpHelp talk13
14CategoryCategory talk15
100PortalPortal talk101
118DraftDraft talk119
126MOSMOS talk127
710TimedTextTimedText talk711
828ModuleModule talk829
1728EventEvent talk1729
Former namespaces
108BookBook talk109
442CourseCourse talk443
444InstitutionInstitution talk445
446Education ProgramEducation Program talk447
2300GadgetGadget talk2301
2302Gadget definitionGadget definition talk2303
2600Topic2601
Virtual namespaces
-1Special
-2Media
Current list

TheTemplate namespace on Wikipedia is used to storetemplates, which containWiki markup intended for inclusion on multiple pages, usually viatransclusion. Although the Template namespace is used for storing most templates, it is possible to transclude and substitute from other namespaces,[1] and so some template pages are placed in other namespaces, such as theUser namespace.

Templates help maintain consistent formatting and aid navigation between articles. They often include optional and/or variable elements controlled byparameters to allow for specialized use. Templates are also used to assist in a large variety ofWikipedia maintenance tasks. Each template has a matchingTemplate talk: page where editors can discuss the design and implementation of the associated template (seeHelp: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 templatepage name surrounded by double curly braces, e.g.{{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 theTemplate: prefix, e.g.[[Template:Disambiguation]]. See§ Linking to templates for other ways to link to a template.

Guidelines

Shortcuts
Further information:Wikipedia:Be bold § Template namespace
  • Templates should not normally be used to storearticle text, as this makes it more difficult to edit the content. They should alsonot 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 – use the article's talk page or other non-article namespaces.
  • Template function should be clear from thetemplate name, butredirects can be created to assist everyday use of very popular templates.
  • High-risk templates should be semi-protected,template protected, or fully protected as appropriate (seeWikipedia:Protection policy). This applies also to any high-use template redirects.
  • Templates should be clearlydocumented as to their usage and scope.
  • Templates should not be used to create lists of links to other articles when acategory,list page, or"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 withsubstitution (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 atWikipedia:Templates for discussion.

Linking to templates

Internal links to template pages may be made by using theTemplate: prefix or itsaliasTM:, e.g.[[Template:Disambiguation]] or[[TM:Disambiguation]]. These links go to a page that directly contains a base template, but subpages such as the template'sdocumentation can be linked directly as well, e.g.[[Template:Disambiguation/doc]].

To link to a template using a display format appropriate for templates, useTemplate:Tl (short for "template link"). For example, to reference the Cleanup template, typing{{tl|Cleanup}} results in{{Cleanup}}. This does not call the template, but the display clearly indicates that the linked object is a template. You can also add parameters usingTemplate:Tlp; for example,{{tlp|Convert|1|m}} displays as{{Convert|1|m}}. Check the template documentation onTemplate:Tl for other options, such as {{tlb}} (bold),{{tlx}} (code),{{tlxi|param1|param2}} (italic parameters),{{tnl}} (no link), and many more.

Suggested practices

Template names

Shortcut

Template names should be made of one or more words, such as{{Train topics}}. The first character is not case-sensitive, so{{cleanup}} and{{Cleanup}} are the same template. All other characters are case sensitive, so{{cfd}} and{{cfD}} are not the same. Template names are easiest to remember if they follow standard English spelling, spacing, and capitalization (also see thenaming conventions for articles). Avoid having templates whose names differ only in case, spacing, or punctuation.

For templates with long names,template redirects (often called shortcuts) can be created for ease of typing. For example, instead of typing{{Template link with subst}} the shortcut{{tls}} is available.

Sandbox for experiments

Main page: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 theTemplate sandbox. You may also use the templatesX1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11, andX12 for experimental purposes. To include a test template, use the form{{X1}} for template X1,{{X2}} for template X2, etc.

Existing templates often each have their ownsandbox and test case pages (especially those that use{{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 newinfobox – which may contain dozens of parameters – your code might look like this:

{{Infobox| header1  = Text of header1| label2   = Text of label2| data2    = Text of data2| etc      = etc}}

Templates using manyconditional expressions often benefit from line spacing, such as the following code used in{{If either}}

{{#if:{{{1|}}}|{{{then|{{{3|}}}}}}|{{#if:{{{2|}}}|{{{then|{{{3|}}}}}}|{{{else|{{{4|}}}}}}}}}}

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, seeWikipedia:Line-break handling.

To avoid unnecessary whitespace, ensure that any<noinclude> tags are placed immediately after the template code. The following code is from{{questions}} and has good line break management.

{{notice|small=yes|If you want to ask a question, please see the[[Wikipedia:Questions]] page for guidance.}}<noinclude>[[Category:Wikipedia help templates]]</noinclude>

Substitution

Main page:Wikipedia:Substitution

Invoking a template using the form

{{subst:name of template(|parameters |...)}}

(that is, insertingsubst: 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 longertranscluded and future changes to the template will not change the text. As aguideline, this method should be used for any short, temporary messages which are removed quickly, such as on User_talk: pages. The standard new user{{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 page: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{{documentation}} template to add a minor description directly onto the template page. As mentioned in§ Line breaks, the first<noinclude> tag should be placed on the same line as the last character of the actual template. For example:

'''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>

Another alternative is to create a formal/doc subpage for the documentation (preferred for templates with multiple parameters, etc.). The{{documentation}} template is still called, but all of the displayed text will be transcluded from the template's /doc subpage.

'''This is a{{{1}}} article.'''<noinclude>{{documentation}}</noinclude>

Modules

Main page:Wikipedia:Lua

Lua modules are sometimes used instead of templates to store reusable material. Reasons for this include usage of module-specific features such asloops 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#invoke 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 thepost-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, {{msg:stub}} was typed instead of {{stub}}. This is no longer necessary.

In Wikipedia's first 35 months, there was no template or transclusion mechanism at all. The pageWikipedia:Boilerplate text was created in September 2002 to collect frequently used text in various Wikipedia processes. TheMediaWiki 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 {{msg: ...}} syntax. This function was replaced with theTemplate namespace during the software upgrade to MediaWiki 1.3 on May 30, 2004. As a function of the "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 asvotes for deletion orVfD) 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 asnested templates andCSS tricks. These undesirable methods led to the development ofm:Extension:ParserFunctions, added in 2006 with MediaWiki 1.7. By 2009, many problems with template readability and complexity still remained (On templates and programming languages). In 2013, in order to address page load times, mostly due to slow template renders,Lua was enabled, creating a Module: namespace for programmers to make use of (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. SeeHelp:Searching for more information.

Pages which contain information on commonly used templates:

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 atWikipedia:Requested templates.

See also

Notes

  1. ^Namespaces from which transclusion is not allowed are specified on a wiki by the variable$wgNonincludableNamespaces
Wikipedia keypolicies and guidelines (?)
Content (?)
P
G
Conduct (?)
P
G
Deletion (?)
P
Enforcement (?)
P
Editing (?)
P
G
Style
Classification
Project content (?)
G
WMF (?)
P
Main namespace
Other namespaces
All namespaces
Navboxes
with templates
Inline images
Help pages
Related topics
Search
Retrieved from "https://en.wikipedia.org/w/index.php?title=Wikipedia:Template_namespace&oldid=1269354873"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp