Assistant for Templates
|
Previous Top Next |
For the Administrator of Templates see: Administrator of Templates
An assistant to insert templates stored in the database application.
|
A template is a Wikipedia 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.
Another method is substitution, where the content of the template is copied into the wikitext
of the target page, just once, when it is saved.
Templates can contain any desired wikitext, including calls to other templates. They have
some limited programming capacities: customizable values (called parameters), calculation
and branchings (using parser functions) and access to wiki-specific variables (magic
words), such as dates, times, and page names. They may also contain tags which define
which parts of the wikitext are to be included when the template is transcluded or
substituted. This means that the appearance of the template page itself need not be the
same as that of the transcluded content (for example, it can contain documentation,
categories, etc. for the template).
To transclude a template in an article type {{template name}} in the wikitext in the point
where the template should appear.
Sintax
The basic transclusion sintaxis given above may be extended with the addition of
parameters, used to control the display. The sintaxis is:
{{template name | parameter | parameter |...}}
The parameters (if any) that can pass to a template, and the way they should be named
depend on the codification of that template. The named parameters may appear in any
order. The superfluous or non-identified parameters will be ignored, while unnamed
parameters will receive default values. If a parameter is defined more than once, the last
value will be taken.
A parameter value may be left blank (the vertical pipe or equal sign may appear before the
following vertical pipe or by the closing braces. This is different from omitting the parameter
leaving it undefined, although the templates are often codified to behave the same way in
both cases.
To call a template is not like calling a variable or function in a programming language: It is
called with a reference and it returns a value. But like functions, some templates accept
parameters that change the layout.
In MediaWiki, the variables have a more specific meaning which distinguish them from the
templates, but both are identified by double braces {{ }} and both return a value.
While the variable names in MediaWiki are all in capital letters (see: Magic Words), the
template names have the same basic characteristics and limitations than all page names;
they are case sensitive (except the first character), lower dashes become spaces, these
cannot contain any of the characters # < > [ ] | { } because are reserved for wiki and HTML
code.
Substitution
Examples with parameters
An example of a template which take parameters is {{about}}. Try typing {{about|how to use
templates|how to use modules|Help:Module}} in the sandbox an it will produce the following
text:
This page is about how to use templates. For how to use modules, see Help:Module.
For how to use modules, see Help:Module.
Other templates, the most complex ones, take named parameters or a combination of
named and unnamed parameters. A simple example is the template Payoff matrix used to
obtain a 2x2 grid. Example:
{{payoff matrix | UL = 5 | UR = 7 | DL = 2 | DR = 9 | Name = Example usage }}
|
left right
5 7 2 9
Example usage
This template is used without defining all possible parameters. The undefined parameters take
default values. The spaces around equal signs are only shown for clarity, but are not
necessary and are ignored evaluating the templates (although this do no happen with the
unnamed parameters.
The names of the parameters are case sensitive. For example: You can not substitute "DR" by
"dr" or "dR". When named parameters are not used, these are ignored.
Infoboxes
Templates for Infoboxes are mostly represented in this repository. Those are more than one-
third of all templates stored in the application. Although the assistant contains by default more
than 80 templates for infoboxes, including 55 of the most commonly used, these are only a
fraction of the total. There are hundreds of templates, too much of them, and the editors are
always creating new templates or improving the existing ones.
Frequently asked questions
Can I use a template in other projects?
Are templates case sensitive?
Yes, except the first character, which can be either uppercase or lowercase.
Can I use a template inside another template?
Yes.
|