Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Help:A quick guide to templates

Page semi-protected
From Wikipedia, the free encyclopedia
Wikimedia project page or help page

This help page is ahow-to guide.
It explains concepts or processes used by the Wikipedia community. It is not one ofWikipedia's policies or guidelines, and may reflect varying levels ofconsensus.
Wikitext

This is a quickoverview of templates. Full details can be found inHelp:Template andmw:Manual:Advanced templates.

Atemplate 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 useMediaWiki parser functions, nicknamed "magic words", a simplescripting language.

Template pages are found in thetemplate namespace. This means any page whose title begins with "Template:", such as "Template:foo", can be used for that purpose. The content from a template titled Template:foo can be added into a Wikipedia page by editing a page and typing{{foo}} into it. When then viewing the page,{{foo}} is automatically replaced by the content of the page "Template:foo". If the page "Template:foo" is later altered, all the pages with{{foo}} in them will change automatically.

Among other things, templates are used to add recurring messages to pages in a consistent way, to addboilerplate messages, and to create navigational boxes.

When a template is automatically expanded and appears on a page, it is said to be "transcluded".

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{{foo|...}} 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.)

Creating, editing, and using templates

You can start a new template in the same way that you wouldstart an article page. The only difference is that its title must start withTemplate:.

Once you have made the template—for exampleTemplate:foo—you can add{{foo}} to the pages that you want to use it on. Every page using this template uses the sameboilerplate text each time that a user visits it. When the template is updated, all pages containing the template tag are automatically updated.

Alternatively, if you do not wish the page to reflect future updates to the template, you can add{{subst:foo}} to the pages on which you want to use the boilerplate text. The system fetches a one-time copy of the template text andsubstitutes it into the page in place of the template tag. If anyone edits the template afterwards, pages that used thesubst: keyword donot update. Sometimes that is what you want.

If the template that you want to edit looks like{{foo}}, you would go to Template:foo to edit it. To get there, type "Template:foo" in the search box (seesearch), or make a wikilink like[[Template:foo]] somewhere, such as in thesandbox, 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 thetemplate 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{{foo}}, an embedded template tag would have additional values separated byvertical bars (|), e.g.{{foo|July|lc=yes}}. HereJuly is the value of the first unnamed parameter;yes is the value of the named parameterlc. Writing the template page for a template with parameters is more complicated than for a template with no parameters. SeeHelp:Template.

Editing existing templates

When you edit a template that is in use, it can affect many pages throughout Wikipedia all at once.

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 thetemplate link template. The primary motivation to do this is in instruction and documentation. A short example is the code:

{{tl|foo}}
generates
{{foo}}

FAQ

How can I find out how to use an existing template?
To see the documentation for the template whose name is "foo", go to "Template:foo".
How do I find out where a template is used?
To list all pages onto which a template is transcluded, useSpecial:WhatLinksHere and type in template:templatename (more info).
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.
Are template names case-sensitive?
Yes, except usually (on most wikis)[1] the first letter.
How can I add parameters?
SeeHelp:Template for instructions.
I edited the template, so why didn't the page it is used on change?
Wikipedia and your computer both store webpagecaches – or saved copies – and don't always show you an updated page. First, try tobypass your browser's cache by pressing⌥ Opt+⌘ Cmd+R,Ctrl+⇧ Shift+R, orCtrl+F5. If that fails, you may need topurge the page's cache (which can be done several different ways). Perhaps the easiest way to do this is by clickingedit on the page in which the template appears, and then clicking onPublish changes without having changed anything – there is no need to fill in theSummary field since there will not be anyhistory of this as a change generated.
Can I move a template to a new name?
Yes, this works in exactly the same way as normalpage 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 withTemplate:. 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'sHelp:Template and Wikimedia'smw:Help:Template, including all of "advanced functioning" help pages listed toward the bottom ofthat page.

Examples

Wikipedia-specific help

About Wikipedia (?)
Help for readers (?)
Contributing
to Wikipedia
 (?)
Getting started (?)
Dos and don'ts (?)
How-to pages and
information pages (?)
Coding (?)
Directories (?)
General
technical help
Special
page
-related
Wikitext
Links anddiffs
Media files: images,
videos and sounds
Other graphics
Templates and
Lua modules
Data structure
HTML andCSS
Customisation
and tools
Automated editing


Retrieved from "https://en.wikipedia.org/w/index.php?title=Help:A_quick_guide_to_templates&oldid=1308725904"
Category:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp