Difference between revisions of "Template:Help:Template parameters"

Ashes of Creation community empowered Wiki
Jump to navigation Jump to search
(Created)
 
(Remove sections)
 
Line 40: Line 40:
 
{{box|Thank you for your help with the wiki Rick!<br/>
 
{{box|Thank you for your help with the wiki Rick!<br/>
 
From the wiki team.}}
 
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:
 
 
<pre>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.</pre>
 
 
Suppose we wish to include this template on the following regular page:
 
 
<pre>My favorite and least favorite things
 
=== Games ===
 
{{Games}}
 
=== Balloons ===
 
I like all balloons!</pre>
 
 
The result has all headings at the same level, which may be confusing to the reader:
 
 
{{box|My favorite and least favorite things
 
<h2> Games </h2>
 
<h2>Games I like</h2>
 
My favorite games are MMOs.
 
<h2> Games I don't like </h2>
 
My least favorite games are those with P2W.
 
<h2> Balloons </h2>
 
I like all balloons!}}
 
 
Instead, we use a template parameter with a default value to adjust the heading levels.
 
 
<pre>My favorite and least favorite things
 
=== Games ===
 
{{Games|====}}
 
=== Balloons ===
 
I like all balloons!</pre>
 
 
Template:Games page:
 
 
<pre>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.</pre>
 
 
The result is much easier to read.
 
 
{{box|My favorite and least favorite things
 
<h2> Games </h2>
 
<h3>Games I like</h3>
 
My favorite games are MMOs.
 
<h3> Games I don't like </h3>
 
My least favorite games are those with P2W.
 
<h2> Balloons </h2>
 
I like all balloons!}}
 

Latest revision as of 17:48, 11 June 2019

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