Help:Templates

From Guild Wars 2 Wiki
Jump to: navigation, search

What is a template?[edit]

A template is a page that is meant to automate parts of other pages, for example navigation bars or infoboxes. Including a template is formally called transclusion. The wiki code of the template is not inserted and saved in the page, just a call to the template. Thus, later changes to a template will automatically occur on every page where the template is used. Templates help present information in a standard manner across multiple pages. The navigation box at the bottom of this page is an example of a template.

Templates on this wiki can be found at Category:Templates.

For specific infoboxes for items, weapons, etc, see Category:Infobox templates

How to use templates[edit]

The minimum syntax required to add a template to a page is:

{{Template name}}

Except for the first letter of the template name, the syntax is case-sensitive.

Parameters

Some templates may require parameters for them to display properly, or to alter the appeareance and functionality for different usages. Parameters act as a placeholder where a specified value can be substituted. Parameters can either be named or numbered starting at 1. For templates that have named parameters, the syntax is:

{{Template name|parameter1=value1|parameter2=value2}}

For templates that have numbered parameters, the parameter name is not necessary.

{{Template name|value1|value2}}

Templates can be written in multiple lines for readability.

{{Template name
| parameter1 = value1
| paremeter2 = value2
}}

Substitution

Templates can be substituted into a page. This is different from transclusion in that the actual wiki code of the template is inserted into the page and saved. Changes to the template will not reflect in pages that have the template substituted. The syntax to substitute a template is:

{{subst:Template name}}

How to create templates[edit]

Templates are created like any other page. Generally, a template is created in the Template namespace. Other namespaces can be used, but the namespace must be included in the template call.

{{Namespace:Template name}}

Parameters

The syntax to add a parameter is:

{{{parameter}}}

A parameter can have a default value that will be used when no value is specified.

{{{parameter|default value}}}

<noinclude>

A template may include information that should not be transcluded such as documentation. The parts of the template that is not meant to be include can be wrapped with a <noinclude> tag. It is preferable to not have any whitespace between the end of the wiki code and the <noinclude> tag.

Template wiki code<noinclude>Text that will not be included</noinclude>

Formatting a template page[edit]

There are no strict formatting guidelines for templates, just try to document everything that the template does and the available parameters. However, the suggested headings for template page are given below.

... template code ...
<noinclude>
== Description ==
This template is designed to produce...

== Usage ==
<!-- example wrapped in pre tags -->
=== Parameters ===
All parameters are required unless specified.
;parameter1
:This parameter determines...
;parameter2
:Optional. This parameter should be set if...

=== Example ===
<!-- pre wrapped example template usage -->
<!-- example template usage -->

[[Category:Formatting templates]]
</noinclude>