From StrategyWiki, the video game walkthrough and strategy guide wiki
Jump to: navigation, search
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[edit]

Template names are prefixed with Template:, 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[edit]

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 <noinclude> 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 [[Category:Templates|{{subst:PAGENAME}}]] or [[Category:Guide-specific templates|{{subst:PAGENAME}}]] category, close the </noinclude> 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 [[Category:Template documentation|{{subst:PAGENAME}}]], surrounded by <noinclude> tags.

Using a template[edit]

Templates are wiki pages which can be used in other pages in three ways:

{{Name}} includes the current content of the page "[[Template:Name]]".
{{subst: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.
{{msgnw:Name}} includes the template in raw wiki syntax, like <nowiki> does

Using parameters in templates[edit]

Description Template text You type… You get…
Template with numbered parameters
 
'''A little thank you...'''<br>
<small>for {{{1}}}.<br>
hugs, {{{2}}}</small>
{{Thank you|all|~~~}}
Someuser
A little thank you…
For all.
Hugs, ~~~~
Template with named parameters
 
'''A little thank you...'''<br>
<small>for {{{reason}}}.<br>
hugs, {{{signature}}}</small>
{{Thank you
|reason=all
|signature=~~~
}}
Someuser
A little thank you…
For all.
Hugs, ~~~~

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

When using the template on a page, you fill in the parameter values, separated by a pipe char (|): {{Thank you|all|~~~}} or - if you have used named parameters {{Thank you|reason=all|signature=~~~}}. 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: {{Thank you|2=~~~|1=all}}.

Control template inclusion[edit]

You can control template inclusion by the use of <noinclude>, <includeonly> and <onlyinclude> tags.

Anything between <noinclude> and </noinclude> 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 <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.

<onlyinclude> is somewhat different. Anything between <onlyinclude> and </onlyinclude> displays everywhere, but everything outside of it is treated as if it was wrapped in <noinclude> 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[edit]

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
{{sidebar
|float=left, right, or none (default: right)
|class=Variant class (e.g. "banner"; default: empty)
|width=Box width (CSS syntax)
|title=Box title
|contents=Box contents
}}
Parameter list
{{sidebar
|float=
|class=
|width=
|title=
|contents=
}}
  • 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)

The user can then simply copy and paste the template for use. Make sure to use <noinclude> tags around everything from the end of the tempate code to the end of the page.

Advanced template usage[edit]

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 {{#if:}} 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 {{#if:}} 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. {{#if:}}) will end abruptly. Typically, {{!}} is used when generating new rows of a table (HTML TR/TD) within a conditional argument.

{{#if:}}[edit]

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:

{{#if:<variable to test>|<what to display if test is not empty>|<what to display if test is empty>}}
Usage of {{#if:}}
You type… You see… Why?
{{#if:{{{1|}}}|not empty|empty}}
empty There is no defined value for the variable {{{1}}}, so it jumps to the default value after the pipe character (which is nothing in this case). This default value of nothing returns the empty value.
{{#if:{{{1|a}}}|not empty|empty}}
not empty Because {{{1}}} is again not defined, so it jumps to the default value of "a". Because "a" is a non-empty string, {{#if:}} returns the not empty value.
{{#if:|not empty|empty}}
empty The parameter being tested is empty, so it returns that value.
{{#if:hello|not empty|empty}}
not empty The string "hello" is not an empty string, so it returns the not empty value.
{{#if:hello|not empty}}
not empty It is possible to skip unneeded parts of the #if construct, in this case, the <what to display if test is empty> part.
{{#if:||empty}}
empty The test parameter was empty, so that was the result. When skipping sections in the middle of the #if construct, you still need the pipes to go to later sections.

{{#expr:}}[edit]

{{#expr:}} 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:

{{#expr:<expression to be evaluated>}}

The operands that can be used in {{#expr:}} are listed below.

Usage of {{#expr:}}
Operator Operation Example
None

{{#expr: 123456789012345}} = 1.2345678901234E+14

{{#expr: 0.000001}} = 1.0E-6

( ) Grouping operators

{{#expr: (30 + 7) * 7 }} = 259

+ Unary + sign

{{#expr: +30 * +7}} = 210

- Unary - sign (negation)

{{#expr: -30 * -7}} = 210

not Unary NOT, logical NOT

{{#expr: not 0 * 7}} = 7
{{#expr: not 30+7}} = 7

* Multiplication

{{#expr: 30 * 7}} = 210

/ Division, same as div

{{#expr: 30 / 7}} = 4.2857142857143

div Division, same as /,
no integer division

{{#expr: 30 div 7}} = 4.2857142857143
{{#expr: 5 div 2 * 2 + 5 mod 2}} = 6

mod "Modulo", remainder of division after truncating both operands to an integer.
Caveat, div and mod are different from all programming languages.

{{#expr: 30 mod 7}} = 2
{{#expr: -8 mod -3}} = -2
{{#expr: -8 mod +3}} = -2
{{#expr: 8 mod 2.7}} = 0
{{#expr: 8 mod 3.2}} = 2
{{#expr: 8.9 mod 3}} = 2

+ Addition

{{#expr: 30 + 7}} = 37

- Subtraction

{{#expr: 30 - 7}} = 23

round Rounds off the number on the left to the power of 1/10 given on the right

{{#expr: 30 / 7 round 3}} = 4.286
{{#expr: 30 / 7 round 0}} = 4
{{#expr: 3456 round -2}} = 3500

= Equality (numerical incl. logical)

{{#expr: 30 = 7}} = 0

<> Inequality, same as !=

{{#expr: 30 <> 7}} = 1

 != Inequality, same as <>, logical xor

{{#expr: 1 != 0}} = 1

< Less than

{{#expr: 30 < 7}} = 0

> Greater than

{{#expr: 30 > 7}} = 1

<= Less than or equal to

{{#expr: 30 <= 7}} = 0

>= Greater than or equal to

{{#expr: 30 >= 7}} = 1

and Logical AND

{{#expr: 4<5 and 4 mod 2}} = 0

or Logical OR

{{#expr: 4<5 or 4 mod 2}} = 1

{{#ifeq:}}[edit]

This function compares a string or numerical value in <parameter to test> to the string or numerical value in <parameter to compare test to>. If you wish to compare strings represented by numbers and numeral operators, enclose the string within "" to force a string comparison. <What to display if test is true> and <what to display if test is false> are optional, but one must be used unless you wish to return absolutely nothing. Also, when testing operations, use {{#expr:}}. The usage for {{#ifeq:}} is as follows:

{{#ifeq:<parameter to test>
|<parameter to compare test to>
|<what to display if test is true>
|<what to display if test is false>
}}
Usage of {{#ifeq:}}
You type… You see…
{{#ifeq:+07|007|yes|no}}
yes
{{#ifeq:"+07"|"007"|yes|no}}
no
{{#ifeq:foo|bar|yes|no}}
no
{{#ifeq:{{#expr:7*5+5}}|40|yes|no}}
yes

{{#switch:}}[edit]

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 {{#switch:}} is as follows:

{{#switch:<parameter to test>
|<value 1> = <what to display if parameter is value 1>
|<value 2> = <what to display if parameter is value 2>
|<value 3> = <what to display if parameter is value 3>
...
|<default if none of the above worked>
}}

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 = <default if none of the above worked> 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.

Usage of {{#switch:}}
You type… You see…
{{#switch:hello|HELLO=foo|Hello=bar|baz}}
baz
{{#switch:hello|HELLO=foo|hello=bar|baz}}
bar
{{#switch:hello|HELLO=foo = 1|Hello=bar = 2|#default=baz = 3}}
baz = 3
{{#switch:hello|HELLO=foo = 1|hello|hi|Hello=bar = 2|#default=baz = 3}}
bar = 2
{{#switch:{{{parametername}}}|<value1>=Whatever|<value2>=Something|Nothing}}
When used in a template, depending on what you pass to "{{{parametername}}}", it could be either "Whatever", "Something", or "Nothing" if nothing is passed.

{{#vardefine:}} and {{#var:}}[edit]

  • Example template: {{im/loz}}

Vardefine is used to declare and set a variable. #var is used to call the value of that variable. Thus, you can separate your code, such as with a #switch, and later use the value of that switch. The only reason to use a #vardefine and var# is if you are going to use the value of a given variable more than once. Otherwise the value of #var can be replaced with the original #switch.

This will print "Value"
{{#vardefine:VariableName|Value}}
{{#var:VariableName}}