I found it relatively hard to find an explanation on how to create a template and Leia - 零亜のレサンテョスイア™ said it would be nice if I made a blog about this.


The only thing I expect you to know before reading this is how to edit pages in general using existing templates, including such that need parameters as {{cai|Vorpal Blade|Shen}} (ShenSquare Shen's Vorpal Blade Vorpal Blade).

I recommend reproducing the examples on own sandboxes for better understanding.

Creating a Template pageEdit

A template page is created as any other page, you can create them on your sandbox for testing purposes. However when creating templates for public use, you should prefix it with "Template:" so it looks like Template:Pending_for_test but can be used as {{pending for test}} (PENDING FOR TEST).


In the most simple template, the text on the template page replaces the {{User:92garfield/SomeTemplate}} so it shows as "Some text".

Sorted ParametersEdit

Parameters are added after the template name, seperated by vertical lines (|) there is one line for each parameter, parameters can be anything you can write on the wiki sorted parameters are also anonymous parameters, they have no name. You call sorted parameters by their position, so the order in which you write them when using the template is important. The parameters are called by the position they are at, enclosed in triple { so the first parameter is used as {{{1}}}. By adding a vertical line (|) behind the number, you can give default values in case the parameter is not used. For empty default value it will look like , when no default value is given and the parameter is not used it will show up as {{{1}}} so you should always state a default value. As I diddn't state that in requirements, you might be wondering "what the fuck do you mean by using parameters?". It's simple, the {{{1}}} in a template page will be replaced by whatever is written behind the first vertical line (|) when using the template.


Example 1
Will expand to:
Infinite monkeys invented a time machine and killed every single unicorn.
It got 3 Parameters each one got a default value.

Example 2
{{User:92garfield/CoolStory|(Parameter 1)|(Parameter 2)|(Parameter 3)}}
Will expand to:
(Parameter 1) invented a (Parameter 2) and killed every single (Parameter 3).

Named ParametersEdit

Named parameters are mostly used for large templates or when they have many optional parameters. When parameters have names, the order doesn't matter it's used by first writeing the name behind a vertical line (|) and the value behind it seperated by a equal sign (=). Named and sorted parameters can be used in one template, for the names of the sorted ones the named ones are not counted. In the template the names are written instead of the numbers, default values are stated the same way as in sorted parameters.


|content11 = healthy
|content21 = more healthy
|content12 = not tasty
|content22 = tasty}}
Expands to:

Vegetables Meat
healthy more healthy
not tasty tasty


Now it gets intresting, functions behave based on parameters, they are used as {{#function:parameter1|parameter2|...}}, they work similarily with templates, but offer additional functionality. he amount of parameters varies, I'm only going to explain the most important functions (that's about oppinion of course). All functions are explained here (or somewhere around there).


The function takes three parameters.
{{#if:input|input is true|input is false}}
The term is expanded to either the second or third parameter based on wether the input is true or false. The input is considered true as long as it's not empty. A string that only contains spaces or line breaks it's considered empty as well. When the input is true, the therm expands to the second parameter, otherwise it will show the third parameter.


Example 1
{{#if:anything|input is true|input is false}}
Expands to:
input is true

Example 2
{{#if: |input is true|input is false}}
Expands to:
input is false


This function takes three parameters.
{{#replace:input|search term|replacement term}}
The function will expand to the input, but all occurrences of the search term replaced with the replacement term.


{{#replace:This text is not supposed to make anysense, it is supposed to serve as a good example.|pp|PP}}
Expands to:
This text is not suPPosed to make anysense, it is suPPosed to serve as a good example.

Question & AnswerEdit

Feel free to ask related questions in comments, in chat or as message to me. If I feel they could be intresting, more frequent or important in some other way, I will post and answer them here. I will however answer any question you ask me, given I know the answer.

Work in progressEdit

This is gonna be continued the next days.
*92Gar†ield~ 20:07, March 26, 2012 (UTC)