Help:Templates


 * Template redirects here. For a list of templates see Category:Templates

If you have standard texts you want to include on several pages, the MediaWiki template feature comes into play (like the tag above which is included in the pages of the Help namespace).

Creating a template
Template names are prefixed with, you create them like any other wiki page.

Templates should only be created to graphically arrange data, and/or to ease the creation of additional pages or elements of pages. Keep in mind that templates should be used to reduce the amount of code on a page via repeated use.

Every template must be placed within a category, either Category:Templates or Category:Guide-specific templates.

If you want to modify a template it's usually good to discuss it within the talk page if it's a major change. Making multiple changes to templates used on multiple pages can cause disastrous effects and bog down the job queue (increasing the server workload), so it's best to discuss changes on the talk page or try your idea in a sandbox before any changes are made. Most widely-used templates, like Game are protected to avoid this, so a discussion is the perfect way to get your ideas heard. Protected templates will require a sysop/admin to make the change.

Categorization, careful naming, and maintaining a hierarchy is key in ensuring that our templates don't get cluttered. Templates are critical for reducing redundancy, but they are powerful tools that must be given respect and much thought so that they don't in themselves become redundant.

Documentation Sub-pages
When a template becomes widely used, such as Game, it's necessary to move the documentation (a.k.a. explanation) of the template to another page.

Rules for creating a documentation subpage:
 * First, start tags immediately after the template code ends. This is followed by the Documentation template, which automatically transcludes the documentation page and a link to it. After adding the or  category, close the tag.
 * The documentation sub-page must be titled "Documentation", as in Template:Game/Documentation. After adding the Documentation template, you can click the red link it creates to go to the properly named page.
 * The sub-page should be categorized by, surrounded by tags.

Using a template
Templates are wiki pages which can be used in other pages in three ways:
 * includes the current content of the page "Template:Name".
 * inserts the content of the page "Template:Name" when you save your text. Subst will use the template one time for the creation of the page; afterwards if the template is updated, the page that subst:template was used on will not have those changes made to them.
 * includes the template in raw wiki syntax, like  does

Using parameters in templates
You can define parameters in templates either numbered as  or named.

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:Thank you you enter your text.

When using the template on a page, you fill in the parameter values, separated by a pipe char (|):  or - if you have used named parameters. 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:.

Control template inclusion
You can control template inclusion by the use of,   and   tags.

Anything between  and   will be processed and displayed only when the page is being viewed directly, not included.

Possible applications are:
 * Categorising templates
 * Interlanguage links to similar templates in other languages
 * Explanatory text about how to use the template

The converse is. Text between  and   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.

is somewhat different. Anything between and displays everywhere, but everything outside of it is treated as if it was wrapped in  tags (so only the stuff in the onlyinclude is included on other pages).

Note that the usual update problems apply -- if you change the categories inside a template, the categories of the referring pages won't be updated until those pages are edited.

Making templates useful
For templates to be effective, users need to find them and be able to use them. When editing, a list of links to all templates used on the page can be found at the bottom of the page, below the edit text box and Save page button. Wikis are not user friendly when it comes to finding, using, and working with templates. A simple technique is to have a usage section on the template page. For example, under a "Usage" heading, you may find a copy/paste-able version of the template, with example content or a short list of the necessary and optional parameters: 🇨🇴 Example content

🇨🇴 Parameter list

🇨🇴 The user can then simply copy and paste the template for use. Make sure to use   tags around everything from the end of the tempate code to the end of the page.
 * Necessary parameters
 * title: Box title
 * contents: Box contents
 * width: Box width (CSS syntax)
 * Optional parameters
 * float: left, right, or none (default: right)
 * class: Variant class (e.g. "banner"; default: empty)

Advanced template usage
We already covered parameters, think of them as variables (temporarily stored data). MediaWiki allows us to look at those variables and check if they even contain anything. What this lets us do is create templates in which only certain parts appear if the data exists within them, for instance in Game and Template:Final Fantasy VII/Boss.

The function is what lets us manipulate wiki code in this way. We can test for existence within a parameter, then display a certain text if it exists, and a certain text if it doesn't. This way we can display and hide text when empty spaces would normally exist. Other parser functions like exist and are used for different purposes. Usage of these functions is outlined below.

Note: use | to replace the use of pipes (the "|" character). If you don't, the conditional argument (e.g. ) will end abruptly. Typically, | is used when generating new rows of a table (HTML TR/TD) within a conditional argument.

The function allows us to test a variable to see if it is empty or not. It returns the first value (value after the first pipe) if it is not empty and the second value (value after the second pipe) if it is. It is used with the syntax:

evaluates a mathematical expression or boolean comparison (where the results are only 1 or 0, for true and false respectively). It is used with the syntax: The operands that can be used in are listed below.

This function compares a string or numerical value in to the string or numerical value in. If you wish to compare strings represented by numbers and numeral operators, enclose the string within "" to force a string comparison.  and  are optional, but one must be used unless you wish to return absolutely nothing. Also, when testing operations, use. The usage for is as follows:

This function allows you to do various things depending on the value of a variable (so you only need one function instead of multiple nested ifeqs). The usage for is as follows: Please note that you may have as many checks as you wish and the default parameter is optional. If you need an equals sign = in your default value, use |#default =  instead. Also, the default parameter, if given, must always be last. Comparisons are case sensitive. "Default" parameters within the statements themselves will just be read as the value to match, and the text displayed will be the next parameter with the equals sign.