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, 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 Template:Infobox 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.

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

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. Wikis are not user friendly when it comes to finding, using, and working with templates. A simple technique is to have a usage on the template page. For example

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 Template:Infobox 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.

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: