Difference between revisions of "Help:Templates"

From Twinsuniverse
Jump to: navigation, search
m
Line 1: Line 1:
{{stub}}
+
{{Help}}A '''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.
  
{{Help}}
+
The implementation of a template in a page is similar to [[Help:Links|linking to a page]], only that except square brackets like in <nowiki>[[Link]]</nowiki>, we use curly braces as in <nowiki>{{Template}}</nowiki>.
  
A '''template''' is an editing technique in MediaWiki, 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.
+
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.
 
+
The implementation of a template in a page is similar to [[Help:Links|linking to a page]], only that except square brackets (<nowiki>[[Link]]</nowiki>), we use curly brackets (<nowiki>{{Template}}</nowiki>.
+
  
 
==Creating a new template==
 
==Creating a new template==
To create a new template, enter the [[Help:Editing|editing]] window of any article, and write the following text anywhere:
+
To create a new template, enter the [[Help:Editing|editing]] mode of any article, and write the following text anywhere:
 
  <nowiki>{{Template name}}</nowiki>
 
  <nowiki>{{Template name}}</nowiki>
 
(replace "Template name" with the name you wish to assign to the template, of course)
 
(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 that:
+
Click the Show preview button, and you will get a red link which looks like this:
 
  [[Template:Template name]]
 
  [[Template:Template name]]
Click on the link, and you will be taken to the template's editing window. Edit it like any other page, and save it. To embed the template in other pages, add the line <code><nowiki>{{Template name}}</nowiki></code> where you want the template displayed, replacing "Template name" with the name of your template.
 
  
==Parametric templates==
+
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.
There is also the possibility to add parameters to templates, which are changeable in every page. To add a parameter to a template, in the template page put '''three''' curly brackets around the word you wish to make a parameter. For example:
+
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 <code><nowiki>{{Template name}}</nowiki></code> where you want the template displayed, replacing "Template name" with the name of your template.
  <nowiki>{{{Name}}}</nowiki>
+
 
Note that parameters are case-sensitive, and "Name" will not be similar to "name".
+
Creating a template is exactly the same as creating a normal [[Help:New article|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:
 +
  <nowiki>{{{name}}}</nowiki>
 +
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:
 
To use a parameter in the target page, use the following order:
Line 31: Line 35:
  
 
For example:
 
For example:
  <nowiki>{{Character|Name=Twinsen}}</nowiki>
+
  <nowiki>{{Character|name=Twinsen}}</nowiki>
  
If there are many parameters in the template, you can also add a line break between them, to make it easier on the eye:
+
And when there are multiple parameters:
  <nowiki>{{Character
+
<nowiki>{{Character|name=Twinsen|race=Quetch|age=Adult}}</nowiki>
|Name=Twinsen
+
 
|Race=Quetch
+
If there are many parameters in the template, you may also put them on a separate line, to make it easier on the eye:
|Size=Medium}}</nowiki>
+
  <nowiki>{{</nowiki>Character
 +
<nowiki>|</nowiki>name=Twinsen
 +
<nowiki>|</nowiki>race=Quetch
 +
<nowiki>|</nowiki>age=Adult
 +
<nowiki>|</nowiki>magical=yes
 +
<nowiki>|</nowiki>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===
 
===Default value for a parameter===
It is possible to define a default value for parameters, which will be used if no value was written for the parameter in the target page. To do so, after the parameter's name in the template page, add "|default text". For example:
+
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:
  <nowiki>{{{Name|Unknown}}}</nowiki>
+
  <nowiki>{{{name|Unknown}}}</nowiki>
  
 
==An example of a template usage==
 
==An example of a template usage==
'''Template:Character:'''
+
===Template:Character===
  <nowiki>{| border="1" align="right" style="background:lightblue; color:black"
+
  <nowiki>{|</nowiki> border="1" cellspacing="0" cellpadding="3" align="right" style="background:lightblue; color:black"
|-
+
<nowiki>|-</nowiki>
|
+
| colspan="2" style="text-align:center; font-size:1.2em" | <nowiki>{{{name|Unknown}}}</nowiki>
<p align=middle><font size=+1>{{{Name}}}</font><br>
+
<nowiki>|-</nowiki>
[[Image:{{{Image}}}]]<br></p>
+
| colspan="2" style="text-align:center" | <nowiki>[[Image:{{{image|default_image.png}}}]]</nowiki>
'''Race:''' {{{Race}}}<br>
+
<nowiki>|-</nowiki>
'''Gender:''' {{{Gender}}}<br>
+
| <nowiki>'''Race:''' || {{{race|unknown}}}</nowiki>
'''Size:''' {{{Size}}}<br>
+
<nowiki>|-</nowiki>
'''Age:''' {{{Age}}}
+
| <nowiki>'''Gender:''' || {{{gender|unknown}}}</nowiki>
|}</nowiki>
+
<nowiki>|-</nowiki>
 +
| <nowiki>'''Size:''' || {{{size|average}}}</nowiki>
 +
<nowiki>|-</nowiki>
 +
| <nowiki>'''Age:''' || {{{age|unknown}}}</nowiki>
 +
<nowiki>|}</nowiki>
  
'''Implementation:'''
+
===Implementation===
  <nowiki>{{Character|
+
  <nowiki>{{Character
Name=Twinsen|
+
|name=Twinsen
Image=TWINSEN.jpg|
+
|image=TWINSEN.jpg
Race=[[Quetch]]|
+
|race=[[Quetch]]
Gender=Male|
+
|gender=Male
Size=Medium|
+
|age=Adult}}</nowiki>
Age=Adult}}</nowiki>
+
 
 +
===Result===
 +
{| border="1" cellspacing="0" cellpadding="3" align="right" style="background:lightblue; color:black"
 +
|-
 +
| colspan="2" style="text-align:center; font-size:1.2em" | Twinsen
 +
|-
 +
| colspan="2" style="text-align:center" | [[Image:TWINSEN.jpg]]
 +
|-
 +
| '''Race:''' || [[Quetch]]
 +
|-
 +
| '''Gender:''' || Male
 +
|-
 +
| '''Size:''' || average
 +
|-
 +
| '''Age:''' || Adult
 +
|}
  
'''Result:'''
+
==Template description page==
{{Character|
+
{{sectsub}}
Name=Twinsen|
+
Image=TWINSEN.jpg|
+
Race=[[Quetch]]|
+
Gender=Male|
+
Size=Medium|
+
Age=Adult}}
+
  
 
[[Category:Twinsuniverse - Help]]
 
[[Category:Twinsuniverse - Help]]

Revision as of 10:50, 1 November 2012

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.

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
File:TWINSEN.jpg
Race: Quetch
Gender: Male
Size: average
Age: Adult

Template description page

Template:Sectsub