Help: Templates

From A Wiki of Ice and Fire
Jump to: navigation, search

Templates provide a means to insert the same content over and over in different (or the same) pages. This saves editors the hassle of duplicating the same text again and again, and also helps ensure consistency. They are commonly used for infoboxes, nav boxes, notices and similar purposes.

Usage and Creation

Template names are prefixed with Template: you 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 "transcluded" into the other page, i.e. it is integrated in the page.

You can then insert {{Welcome}} at any point of any page where you wish to welcome someone. Suppose it is used in 100 pages. If you then change the template contents to:

Hi there! Welcome to this wonderful wiki.

and revisit any of the 100 pages where the template was used, you'll see the new text instead of the original one. In this way, you have changed the content of 100 pages without editing them, because the template is transcluded into these pages.

This is the basic mechanism. There are several additional features of transclusion that enrich this mechanism and make templates very useful.

Specific Templates Usage

As mentioned above, Templates will generally shown in the {{Template name}} format.

See Templates Overview for an Overview of the most important and commonly used Templates, usage. Category:Templates should cover all templates used in the wiki, categorized into the various subcategories. Also you can check the usage of all the specific templates used on that page, to do that while in Edit mode, you can find a list of them at the bottom, clicking on any of them takes you to it's page where you can find it's specific Usage information.

Creating Advanced Templates

Template with numbered parameters
 
'''A little thank you...'''<br>
<small>for {{{1}}}.<br>
hugs, {{{2}}}</small>
You type You get
{{Thankyou|all|Joe}}
Example sunflower image
A little thank you...
for all.
hugs, Joe
with named parameters
 
'''A little thank you...'''<br>
<small>for {{{reason}}}.<br>
hugs, {{{signature}}}</small>
You type You get
{{Thankyou
|reason=all
|signature=Joe}}
Example sunflower image
A little thank you...
for all.
hugs, Joe

To enrich the mechanism, You can define parameters to be passed to a template when it is transcluded. Parameters allow the template to produce different contents or have different behaviors. You can define parameters in templates either numbered as {{{1}}} or named {{{param}}}.

Example: you want a little thank you note you can put other users on their talk page with a reason and your signature. In the Template:Thankyou you enter your text.

When using the template on a page, you fill in the parameter values, separated by a pipe char (|): {{Thankyou|all|Joe}}. For named parameters use "name=value" pairs separated by a pipe char: {{Thankyou|reason=all|signature=Joe}}. The advantage of using named parameters in your template is that they are flexible in order. It also makes the template easier to understand if you have many parameters. If you want to change the order of numbered parameters, you have to mention them explicitly: {{Thankyou|2=Joe|1=all}}.

Includes

You can control which parts of the template will be used, using the <noinclude> and <includeonly> tags.

Each template has two sections, the template itself and the information on how to use it. Obviously you want the Usage information only to show on the template page when view directly and not on every page who use it... so we put it in <noinclude>

Similarly if you want a part of the template to be shown/used only when it's included, for example delete template, you want to add all the pages it's on to the delete Category not the delete template it self, you use the <includeonly> tag.

The converse is <includeonly>. Text between <includeonly> and </includeonly> will be processed and displayed only when the page is being included. The obvious application is to add all pages containing a given template to a category.

Documentation

For templates to be effective users need to find them and be able to use them. So make sure you document your templates to make it easier for the rest to use them, For example

==Usage==
Allows to establish a link to a subject:
{{NameOfTemplate|Term1+Term2+Term3}}

This example may seem trivial but it's get easily complicated when your template has few dozen variables and states. Check out Templates Overview for an Overview of the most important and commonly used Templates, usage; and Category:Templates that should cover all templates used in the wiki, categorized into the various subcategories.


See Also