Help:Templates

Ashes of Creation community empowered Wiki
Revision as of 02:36, 16 October 2017 by Wikiadmin (talk | contribs) (Minor edits)

Jump to navigation Jump to search

Templates allow text to be included on several pages without duplicating the text.

Creation

Templates are standard wiki pages whose content is designed to be embedded inside other pages. Templates follow a convention that the name is prefixed with "Template:". Besides this, you can create them like any other wiki page.

The simplest use of templates is as follows. If you create a page called "Template:Welcome" with contents:

Hello! Welcome to the wiki.

you'll have created your first template! If you then insert the code:

{{Welcome}}

in any other page, when that page is viewed the text

Hello! Welcome to the wiki.

will appear instead of {{Welcome}}. The template content is "embedded" into the other page.

Parameters

Parameters are used to pass information to a template when it is embedded. Parameters allow the template to produce different contents or have different behaviors.

Suppose you wish to insert a thank you note on a page with the name of the person being thanked embedded in the text. Create a template called "Template:Thankyou" as follows:

Thank you for your help with the wiki {{{1}}}!

You can then use this template by specifying the person's name as a parameter to it:

{{Thankyou|Rick}}

Notice the use of {{{1}}}. This is the way to identify, within templates, the parameters that will be passed in when the template is used. Note that, within the template, each parameter is surrounded by three braces: {{{ }}}.

When using the template on a page, you fill in the parameter values, separated by a "pipe" character (|).

The result will look appear as:

Thank you for your help with the wiki Rick!

Default parameter values

Suppose we add a second parameter to the last example, to say who the thank you is from. Such as:

Thank you for your help with the wiki {{{1}}}!<br/>
From {{{2}}}.

If the template is called without the second parameter {{Thankyou|Rick}}, the result would be

Thank you for your help with the wiki Rick!
From .

To avoid this situation, you can use a default parameter value inside the template. The output will take on this value if the parameter is not being passed.

Thank you for your help with the wiki {{{1}}}!<br/>
From {{{2|the wiki team}}}.

Now if the template is called without the second parameter, the result would be

Thank you for your help with the wiki Rick!
From the wiki team.

Templated headings

We use templates with default parameters to adjust the heading levels inside templates to match those of the including page. For example: The template "Template:Games" contains headings and sub headings as follows:

Games can be roughly divided into two types.
=== Games I like ===
My favorite games are MMOs.
=== Games I don't like ===
My least favorite games are those with P2W.

Suppose we wish to include this template on the following regular page:

My favorite and least favorite things
=== Games ===
{{Games}}
=== Balloons ===
I like all balloons!

The result has all headings at the same level, which may be confusing to the reader:

My favorite and least favorite things

Games

Games I like

My favorite games are MMOs.

Games I don't like

My least favorite games are those with P2W.

Balloons

I like all balloons!

Instead, we use a template parameter with a default value to adjust the heading levels.

My favorite and least favorite things
=== Games ===
{{Games|====}}
=== Balloons ===
I like all balloons!

Template:Games page:

Games can be roughly divided into two types.
{{{1|===}}} Games I like {{{1|===}}}
My favorite games are MMOs.
{{{1|===}}} Games I don't like {{{1|===}}}
My least favorite games are those with P2W.

The result is much easier to read.

My favorite and least favorite things

Games

Games I like

My favorite games are MMOs.

Games I don't like

My least favorite games are those with P2W.

Balloons

I like all balloons!