This is a quick overview of templates. Full details can be found in Help:Template, Wikipedia:Templates and m:Help: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. Most templates are scripts using MediaWiki parser functions, nicknamed "magic words", a simple scripting language.
Template pages are found in the template 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 add boilerplate 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).
You can start a new template in the same way that you would start an article page. The only difference is that its title must start with
Once you have made the template—for example Template:foo—you can add
((foo)) to the pages that you want to use it on. Every page using this template uses the same boilerplate 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 and substitutes it into the page in place of the template tag. If anyone edits the template afterwards, pages that used the
subst: keyword do not 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 (see search), or make a wikilink like
[[Template:foo]] somewhere, such as in the 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 used, it is suggested to use sandboxes, as described in the template sandbox and test cases how-to guide.
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 by vertical bars (|), e.g.
July is the value of the first unnamed parameter;
yes is the value of the named parameter
lc. Writing the template page for a template with parameters is more complicated than for a template with no parameters. See Help:Template.
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.
How can I find out how to use an existing template?
How do I find out where a template is used?
Can I use a template in more than one project?
Are templates case-sensitive?
How can I add parameters?
I edited the template, so why didn't the page it is used on change?
Can I move a template to a new name?
Can I use a template within a template?
How do I add a new template?
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?