Difference between revisions of "Help:Templates"

From Twinsuniverse
Jump to: navigation, search
m
m
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{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.
+
{{Infobox 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.
  
 
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>.
 
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>.
Line 35: Line 35:
  
 
For example:
 
For example:
  <nowiki>{{Character|name=Twinsen}}</nowiki>
+
  <nowiki>{{Infobox Character|image=Twinsen.jpg}}</nowiki>
  
 
And when there are multiple parameters:
 
And when there are multiple parameters:
  <nowiki>{{Character|name=Twinsen|race=Quetch|age=Adult}}</nowiki>
+
  <nowiki>{{Infobox Character|image=Twinsen.jpg|race=Quetch|age=Adult}}</nowiki>
  
 
If there are many parameters in the template, you may also put them on a separate line, to make it easier on the eye:
 
If there are many parameters in the template, you may also put them on a separate line, to make it easier on the eye:
  <nowiki>{{</nowiki>Character
+
  <nowiki>{{Infobox Character
  <nowiki>|</nowiki>name=Twinsen
+
  |image=Twinsen.jpg
  <nowiki>|</nowiki>race=Quetch
+
  |race=Quetch
  <nowiki>|</nowiki>age=Adult
+
  |age=Adult
  <nowiki>|</nowiki>magical=yes
+
  |magical=yes
  <nowiki>|</nowiki>size=Average}}
+
  |size=Average
 +
}}</nowiki>
  
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.
+
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 very 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.''
 
'''''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.''
Line 54: Line 55:
 
===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 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:
 
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>{{{race|Unknown}}}</nowiki>
  
 
==An example of a template usage==
 
==An example of a template usage==
 
===Template:Character===
 
===Template:Character===
  <nowiki>{|</nowiki> border="1" cellspacing="0" cellpadding="3" align="right" style="background:lightblue; color:black"
+
An example template could be the following. This is just an example, the real [[Template:Infobox Character|Character]] template is a little more complex;
  <nowiki>|-</nowiki>
+
  <nowiki>{| border="1" cellspacing="0" cellpadding="3" style="background:lightblue; color:black; float:right"
  | colspan="2" style="text-align:center; font-size:1.2em" | <nowiki>{{{name|Unknown}}}</nowiki>
+
  |-
  <nowiki>|-</nowiki>
+
  | colspan="2" style="text-align:center; font-size:1.2em" | <nowiki>{{{name|Unknown}}}
  | colspan="2" style="text-align:center" | <nowiki>[[Image:{{{image|default_image.png}}}]]</nowiki>
+
  |-
  <nowiki>|-</nowiki>
+
  | colspan="2" style="text-align:center" | <nowiki>[[Image:{{{image|default_image.png}}}]]
  | <nowiki>'''Race:''' || {{{race|unknown}}}</nowiki>
+
  |-
  <nowiki>|-</nowiki>
+
  | '''Race:''' || {{{race|unknown}}}
  | <nowiki>'''Gender:''' || {{{gender|unknown}}}</nowiki>
+
  |-
  <nowiki>|-</nowiki>
+
  | '''Gender:''' || {{{gender|unknown}}}
  | <nowiki>'''Size:''' || {{{size|average}}}</nowiki>
+
  |-
  <nowiki>|-</nowiki>
+
  | '''Size:''' || {{{size|average}}}
  | <nowiki>'''Age:''' || {{{age|unknown}}}</nowiki>
+
  |-
  <nowiki>|}</nowiki>
+
  | '''Age:''' || {{{age|unknown}}}
 +
  |}</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
|age=Adult}}</nowiki>
+
|age=Adult
 +
}}</nowiki>
  
 
===Result===
 
===Result===
{| border="1" cellspacing="0" cellpadding="3" align="right" style="background:lightblue; color:black"
+
{| border="1" cellspacing="0" cellpadding="3" style="background:lightblue; color:black; float:right"
 
|-
 
|-
 
| colspan="2" style="text-align:center; font-size:1.2em" | Twinsen
 
| colspan="2" style="text-align:center; font-size:1.2em" | Twinsen
Line 96: Line 99:
 
| '''Age:''' || Adult
 
| '''Age:''' || Adult
 
|}
 
|}
 +
The result is on the right. The rest of the page flows around it because of the "float" style statement above. Floating is convenient for saving space, most infoboxes use this.
  
 
==Template description page==
 
==Template description page==
 
{{sectstub}}
 
{{sectstub}}
 
[[Category:Twinsuniverse - Help]]
 

Latest revision as of 12:12, 8 December 2012

Help Contents
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.

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:

{{Infobox Character|image=Twinsen.jpg}}

And when there are multiple parameters:

{{Infobox Character|image=Twinsen.jpg|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:

{{Infobox Character
 |image=Twinsen.jpg
 |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 very 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:

{{{race|Unknown}}}

An example of a template usage

Template:Character

An example template could be the following. This is just an example, the real Character template is a little more complex;

{| border="1" cellspacing="0" cellpadding="3" style="background:lightblue; color:black; float:right"
 |-
 | colspan="2" style="text-align:center; font-size:1.2em" | <nowiki>{{{name|Unknown}}}
 |-
 | colspan="2" style="text-align:center" | <nowiki>[[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
Twinsen.jpg
Race: Quetch
Gender: Male
Size: average
Age: Adult

The result is on the right. The rest of the page flows around it because of the "float" style statement above. Floating is convenient for saving space, most infoboxes use this.

Template description page

  This section is a stub [list all]. You can help the Twinsuniverse by expanding it.