Difference between pages "Help:Templates" and "MediaWiki:Email"

Ashes of Creation community empowered Wiki
(Difference between pages)
Jump to navigation Jump to search
m (Minor edits)
 
(Created page with "Wiki Admin (no-reply)")
 
Line 1: Line 1:
[[mw:Help:Templates|Templates]] allow text to be included on several pages without duplicating the text.
+
Wiki Admin (no-reply)
 
 
== Creation ==
 
 
 
Templates are standard wiki pages whose content is designed to be [[mw:Special:MyLanguage/Transclusion|embedded]] inside other pages. Templates follow a convention that the name is prefixed with "<code>Template:</code>". Besides this, you can [[Help:Starting a new page|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:
 
 
 
<pre>Hello! Welcome to the wiki.</pre>
 
 
 
you'll have created your first template! If you then insert the code:
 
 
 
<nowiki>{{Welcome}}</nowiki>
 
 
 
in any other page, when that page is viewed the text {{box|Hello! Welcome to the wiki.}} will appear instead of <code><nowiki>{{Welcome}}</nowiki></code>. 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:
 
 
 
<pre>Thank you for your help with the wiki {{{1}}}!</pre>
 
 
 
You can then use this template by specifying the person's name as a parameter to it:
 
 
 
<nowiki>{{Thankyou|Rick}}</nowiki>
 
 
 
Notice the use of <code><nowiki>{{{1}}}</nowiki></code>. 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: <code><nowiki>{{{ }}}</nowiki></code>.
 
 
 
When using the template on a page, you fill in the parameter values, separated by a "pipe" character (<code>|</code>).
 
 
 
The result will appear as:
 
 
 
{{box|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:
 
 
 
<pre>Thank you for your help with the wiki {{{1}}}!<br/>
 
From {{{2}}}.
 
</pre>
 
 
 
If the template is called without the second parameter <nowiki>{{Thankyou|Rick}}</nowiki>, the result would be
 
 
 
{{box|Thank you for your help with the wiki Rick!<br/>
 
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.
 
 
 
<pre>Thank you for your help with the wiki {{{1}}}!<br/>
 
From {{{2|the wiki team}}}.
 
</pre>
 
 
 
Now if the template is called without the second parameter, the result would be
 
 
 
{{box|Thank you for your help with the wiki Rick!<br/>
 
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!}}
 
 
 
[[Category:Help]]
 

Latest revision as of 14:09, 16 October 2017

Wiki Admin (no-reply)