Help:Templates
Template:HelpA template is an editing technique here on the Twinsuniverse, which enables displaying the contents of one page in another, without copying and pasting. A template is a page which can be "planted" in another, and is used to avoid duplications and maintain consistency. A page that uses a template, will update the displayed contents of that template automatically, when the template is changed.
The implementation of a template in a page is similar to linking to a page, only that except square brackets like in [[Link]], we use curly braces as in {{Template}}.
One of the powerful features of templates, is the ability to pass in parameters. This has the result that a template can be rendered differently on every page, depending on the value of the used parameter. This will be discussed further below.
Contents
Creating a new template
To create a new template, enter the editing mode of any article, and write the following text anywhere:
{{Template name}}
(replace "Template name" with the name you wish to assign to the template, of course)
Click the Show preview button, and you will get a red link which looks like this:
Template:Template name
Normally this would translate to using the template called "Template:Template name", but because it doesn't exist yet, a red-link is created instead.
If you click on the link, you will be taken to the template's editing mode to create it. Edit it like any other page, and save it. To embed the template in other pages, add the line {{Template name}}
where you want the template displayed, replacing "Template name" with the name of your template.
Creating a template is exactly the same as creating a normal new article page, as described under "Creating the link". The only difference is that templates always have the "Template:" prefix in their pagename. This makes it easy to recognise a template when you see one.
Note: Creating a template in a different way might not automatically include the "Template:" prefix in the name, in which case it will be recognized as a normal page. Normal pages may still be moved into the template namespace manually though.
Using parameters
There is also the possibility to add parameters to templates, which are dynamic for every page. To add a parameter to a template, in the template page put three curly braces around the word you wish to make a parameter. For example:
{{{name}}}
Note that parameters are case-sensitive, so "Name" is not the same parameter as "name".
To use a parameter in the target page, use the following order:
- {{
- Template name
- |
- Parameter name
- =
- Parameter's value
- }}
For example:
{{Character|name=Twinsen}}
And when there are multiple parameters:
{{Character|name=Twinsen|race=Quetch|age=Adult}}
If there are many parameters in the template, you may also put them on a separate line, to make it easier on the eye:
{{Character |name=Twinsen |race=Quetch |age=Adult |magical=yes |size=Average}}
The naming convention for parameters is all lowercase, and preferably very short, while remaining clear about its meaning and use. So names like "specialabilities" would be too long ("abilities" would be better), "line" might not be very meaningful, and "mcdfc" would be too difficult to understand. Names should be intuitive, so a user can deduct how to use it from it's name.
Note: It is recommended to create a description page for a template, more about that below, where the proper use of parameters are explained for the particular template. It should be avoided however, to rely on the descriptions on that page when naming parameters.
Default value for a parameter
It is possible to define a default value for parameters, which will be used if no value was given for the parameter in the target page. To do so, after the parameter's name in the template page, add "|default text". For example:
{{{name|Unknown}}}
An example of a template usage
Template:Character
{| border="1" cellspacing="0" cellpadding="3" align="right" style="background:lightblue; color:black" |- | colspan="2" style="text-align:center; font-size:1.2em" | {{{name|Unknown}}} |- | colspan="2" style="text-align:center" | [[Image:{{{image|default_image.png}}}]] |- | '''Race:''' || {{{race|unknown}}} |- | '''Gender:''' || {{{gender|unknown}}} |- | '''Size:''' || {{{size|average}}} |- | '''Age:''' || {{{age|unknown}}} |}
Implementation
{{Character |name=Twinsen |image=Twinsen.jpg |race=[[Quetch]] |gender=Male |age=Adult}}
Result
Twinsen | |
Race: | Quetch |
Gender: | Male |
Size: | average |
Age: | Adult |
Template description page
This section is a stub [list all]. You can help the Twinsuniverse by expanding it. |