Help:Templates

From USApedia
(Redirected from Template)
Introduction to templates
Basic formatting of templates
Introduction to template variables
Help
Getting Started
Picking a UsernameTeach Yourself Wiki
Policies and guidelines
USApedia:Copyrights
The USApedia Interface
Left NavigationToolbox Discussion/Talk PageEdit & HistorySearchLog in & Create an Account
Editing USApedia
Creating a new pageCreating your user page • Editors (Visual/Enhanced) • Editing toolbarCheat SheetMagic wordsTable of Contents
Links
Internal linkExternal linkInterWiki linkCategory link Reference links
Images and Media
File Upload Guidelines for USApediaHow to upload new versions of filesImage mapNaming Conventions for FilesUpload documents
Tracking Changes
Recent Edits on USApediaArticle historyReverting to an earlier versionWatchlistHow to add a page to your watchlist
Asking Questions
Using talk pagesHelp:CommentStreams
Resources and Lists
Categories InfoboxHelp:Templates
Account settings and maintenance
Change your preferences Confirm your email address
Technical information
The MediaWiki softwareParser functions
All topics
view · talk · edit

A template is a USApedia page created to be included in other pages. Templates usually contain repetitive material that might need to show up on any number of articles or pages. They are commonly used for Boilerplate messages, standard warnings or notices, infoboxes, navigational boxes and similar purposes.

The most common method of inclusion is called transclusion, where the wikitext of the target page contains a reference to the template, using the {{Template name}} syntax.

When template data is added, templates can be editing using forms.

See Help:TemplateWikipedia Logo.png and Help:TemplateMediawiki logo.svg for additional details.

Find a template

The Template directory is a good place to start as well as:

Adding a template

There are different ways of adding a template, based on the Editor you are using.

VisualEditor

Enhanced editor

To add a template using enhanced editor:

  • Add {{
  • Type or paste the name of the template
  • Add any parameters
  • Close with }}

Infoboxes

  • See Template:Infobox for background and use cases. These templates are used on the upper right-hand side of a page to provide a basic summary of information about a topic.
  • See Category:Infobox templates for a list of infobox templates currently available.

Navboxes

Gardening

See USApedia:Maintenance for a list of gardening templates.

Template Sandbox

The Test Template was specifically created for USApedians to to test out ideas and functionality.

Noinclude, includeonly, and onlyinclude

By default, when a template is transcluded (or substituted), the entire wikitext (code) of the template page gets included in that of the target page. However it is possible to modify that behaviour, using tags that specify which parts of the template code are to be included. This makes it possible to avoid transcluding information intended for display only on the template page itself, such as the template's documentation, categories and interwiki links. It is also possible to have parts of the code be transcluded, but not be processed on the template page itself (e.g. categories to be applied to the target pages which do not apply to the template). The tags are as follows

  • <noinclude>...</noinclude> — the text between the <noinclude> tags will not be included when the template is transcluded (substituted)
  • <includeonly>...</includeonly> — the text between the <includeonly> tags will be transcluded (substituted), but will not be processed on the template's own page
  • <onlyinclude>...</onlyinclude> (not often used) — specifies that nothing on the page except what appears between the <onlyinclude> tags will be transcluded (substituted)

Perhaps the most common issue with the use of these blocks is unwanted spaces or lines. It is important to remember that the effect of these tags ends immediately after the last angle bracket, not on the next line or with the next visible character.

These tags can be nested inside each other, though (for a given page) this really only applies to the <onlyinclude> tag; nesting <includeonly> and <noinclude> tags is fairly pointless. Be careful not to split the tags, however. Constructions like this &lt;onlyinclude&gt; abc &lt;includeonly&gt; def &lt;/onlyinclude&gt; ghi &lt;/includeonly&gt; will not work as expected. Use the "first opened, last closed" rule that is standard for XML.

Standards templates to be used on template pages

Usage syntax

Parameters

Shortcuts:
H:PARAMETER
WP:PARAMETER

The basic transclusion syntax given above can be extended by the addition of parameters, which are used to control the template's output. The syntax for this is {{Template name|parameter|parameter|...}} where Template name is the name of the template, and each parameter may either contain just a value (these are called Template:Dfn) or be of the form name=value (Template:Dfn). The first, second, third, etc. unnamed parameters will be given the names 1, 2, 3, etc.

Whitespace characters (spaces, tabs, returns) are stripped from the beginnings and ends of named parameter names and values, but not from the middle: thus {{ ... | myparam = this is a test }} has the same effect as {{ ... |myparam=this is a test}}. This does not apply to unnamed parameters, where all whitespace characters are preserved.

Which parameters (if any) can or should be passed to a template and how they are to be named depends on the coding of that template. Named parameters can be defined in any order. Superfluous or misnamed parameters will be ignored; undefined parameters will be assigned default values. If a parameter is defined more than once, the last value takes effect.

The value of a parameter can be the empty string, such as when the pipe or equals sign is followed immediately by the next pipe or the closing braces. This is different from omitting the parameter altogether, which leaves it undefined, although templates are often coded so as to behave the same in both cases.

Parameters can be specified (and will do nothing) even if not represented in the template's code. For example, |reason= is frequently used as a pseudo-parameter to explain briefly in the wikisource why the template was placed.[lower-alpha 1] Some templates call Module:Check for unknown parameters to warn the editor if a parameter is being used that is not accounted for in the template's code; this is mostly used for infoboxes and other templates with a large number of complicated parameters, where the presence of an unknown one is usually an unintentional error. If you update such a template to include a new parameter, its call to the module must also be updated to include the new parameter.

Calling

Using a template is much like calling a function in a programming language – call it, and it returns a value (the output). Like functions, some templates accept parameters that change the output.

In MediaWiki, the wiki software that Wikipedia uses, variables have a more specific meaning that distinguishes them from templates, but they are both identified by double braces {{ }} and they both return a value.

Whereas MediaWiki variable names are all uppercase, template names have the same basic features and limitations as all page names: they are case-sensitive (except for the first character); underscores are parsed as spaces; and they cannot contain any of these characters: # < > [ ] | { }. This is because those are reserved for wiki markup and HTML.

The number sign # is called a fragment identifier because it denotes a fragment or section of a document (such as a section in a Wikipedia article). Although it can be used to link to a section of a template page (like Template:Portal#Example), there is no reason to put a fragment identifier or fragment name in a template reference. In {{Portal#Location|Books}}, for example, the string #Location has no purpose and is thus ignored.

Substitution

When a template is substituted, its content is hard-coded in the page rather than transcluded. To learn how and when to substitute a template, see Help:Substitution § When to use substitution.

Icons that are good for templates

These icons either are or can be useful to spruce up templates.

Other icons can be found in the icons category.

Template:USApedia

References

  1. Some templates, such as {{Requested move}}, have code to display |reason= as visible output; whether to do so is determined on a template-by-template basis.