League of Legends Wiki

Comments3

Tutorial on creating Templates

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

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.

Introduction

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}} (Shen Shen's Vorpal Blade.png Vorpal Blade).

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

Creating a Template page

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).

Example

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

Sorted Parameters

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.

Examples

Example 1
{{User:92garfield/CoolStory}}
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 Parameters

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.

Example

{{User:92garfield/NamedParameters
|content11 = healthy
|content21 = more healthy
|content12 = not tasty
|content22 = tasty}}
Expands to:

Vegetables Meat
healthy more healthy
not tasty tasty

Functions

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).

if

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.

Examples

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

replace

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.

Example

{{#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 & Answer

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 progress

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

Also on Fandom

Random Wiki