When reading this lesson, you may find it beneficial to read the introduction to Namespaces below

Templates are repetitive elements used on multiple pages, or in other words, things that appear on multiple pages exactly the same. Templates are generally rather complex codes that would be tedious to write for multiple pages individually and are almost always based on tables, which will be discussed in a different lesson. Tables can essentially be classified into three groups, keeping in mind that they will all be discussed later in the lesson:

  • No parameter
These are more to the effect of those described above in that they are all exactly the same and cannot be changed on a page by page basis. An example of this is Template:Stub.
  • Simple parameter
These are slightly different, in that they have one or more area that can be changed slightly (a parameter) on a page by page basis. They are still considerably simple. An example of this is Template:D.
  • Complex parameter.
These generally have many parameters and require a different format when writing than the other two types of templates. An example of this is [[Template:Metal item]].

What do templates look like?

The following is an example user page, which uses templates quite a bit more than most pages.


My Userpage
Hello and welcome to my userpage!
About Me

I joined the wiki in 2010 when I was told I should use it by another player. My favourite skill is Woodcutting and I like to revert vandalism when I am on the wiki.


Cape of Validation detail.png
This user plays RuneScape
as Wikian99.
$$$ This user's trade limit had reached the maximum of 60,000 coins with 270 or more quest points before the return of Free Trade.
Wooden shield.png This user is somewhat noobish.

The above user page uses the following templates:

  • No Parameter
  • Simple Parameter
    • {{Header Tab}} - the "About Me" section sub-header with multiple parameters for colour and text.
    • {{Userbox/RS name}} - A Userbox displaying one's name, with a single parameter for the name of the player.
  • Complex Parameter
    • {{Header}} - The entire userpage was within a header, which is a more attractive way to display information within one's userspace.

What does this look like in edit mode?

Templates are rather similar to Wiki-links with the exception that they use a different kind of Bracket than the wiki-links, namely braces (wiki-links have square brackets). In edit mode, the above userpage would look like this. One will be shown using the templates, the other with the raw code.

How do I create a template?

Creating a template is rather simple if you know how. You simply have to create a page in the Template: namespace and write the template to do what you want.

Creating a No Parameter Template

No parameter templates are the easiest to write. Assume you want to write a template that says "I like to edit the RuneScape Wiki." All you would have to do is create a new page starting with "Template:" (being sure there is no space between the ":" and the first letter of your template title) and write the page to say "I like to edit the RuneScape Wiki." Assume that the name of the template is "WikiLike". In order to use the template, you would simply have to write "{{WikiLike}}" on a page. Using a template is similar to linking to an article, but templates use two brackets whereas links use two square brackets.

Creating a Simple Parameter Template

Creating a template with parameters is actually pretty easy to do. When you're writing the template, replace the section that you want to vary (the parameter itself) with {{{1}}} (a number surrounded by three sets of brackets, as opposed to the two needed to use a template). So, let's assume that the name of the template is WikiLike, as above, and you want it to say "This user likes the wiki because of insert reason here." Therefore, the syntax for that template would be "This user likes the wiki because of {{{1}}}." Then, when you are using the template, you would write "{{WikiLike|the free cookies}}". The result of this would be "This user likes the wiki because of the free cookies."

The fact that the name of the parameter is 1 means that it will be the first parameter after the template title. You can have more than one parameter as long as you change the number for each, unless of course you want two instances to be changed by the same parameter. Let's assume you want to add yet another parameter to WikiLikes, thus making it say this: "This user likes the wiki because of reason one and reason two." The syntax for that when writing the template would be "This user likes the wiki because of {{{1}}} and {{{2}}}." When using the template, the syntax would be "{{WikiLikes|the free cookies|the clan chat}}". The result of this would be "This user likes the wiki because of the free cookies and the clan chat."

Creating a Complex Parameter template

When you have many parameters, it is almost always best to organize it into a complex parameter template. The only difference is that it uses words in place of numbers for the parameter names, and the syntax when using the template is slightly different.

Let's take our WikiLikes template again as the example, only this time we will be using the complex parameters in place of the simple ones. This time we will be adding color as well as our two reasons. Take this example: "This user likes the wiki because of the free cookies and the clan chat." The syntax used when writing the template was <span style="color:{{{color}}}">"This user likes the wiki because of {{{first reason}}} and {{{second reason}}}."</span>

When using the template, the syntax will be a little different. Assume you want the color to be green again and you want to keep your previous two reasons.

{{WikiLikes
|color = green
|first reason = the clan chat
|second reason = the free cookies
}}

The only difference is that you have to use slightly different syntax to spell out what parameter you're defining.

if, switch, and defaults

This section is quite a bit more advanced and may not be covered during the lesson as it is rather difficult to understand.

if

There are certain times when you only want areas to text to appear in templates if a certain parameter is present. The only parameter used in the template creates a link to a user's unblock request, but only if the parameter is used at all. This uses something called "#if".

If we take WikiLikes and have the second parameter present, we would likely not want everything after the first parameter to appear unless we are using it. After all, it would be rather strange to see "This user likes the wiki because of the clan chat and {{{2}}}", which is exactly what you would see if you did not use #if.

The syntax to make the second parameter areas conditional to the parameter's presence is this: This user likes the wiki because of {{{1}}} {{#if:{{{2|}}}|and {{{2}}}}}., meaning that everything within the #if brackets will only appear if the second parameter is used.

Think of #if kind of like a template. It starts with {{#if:, and then is followed by defining what parameter you want it to apply to. So, we want it to apply to the second parameter, so the syntax is {{{2|}}}. The line after "2" is important to ensure that the template does not confuse it for the parameter itself, so be sure to remember that after the parameter name. After {{{2|}}} comes another line to start the condition. Everything after this line but before the end of the condition, that being a "}}" will only appear if your using the second parameter. Chances are you will want to include the parameter itself within the #if condition, though there are some situations where this is not the case.

switch

Sometimes you want different inputs to have different outputs. What if you have a few set reasons you want people to use? You can put them all on a sort of switch using "#switch".

First of all, let's assume we will use numbers to assign to each of the three reasons we will use. These will be the numbers used in our example.

  • the clan chat → 1
  • the free cookies → 2
  • the free information → 3
  1. switch is similar to #if in syntax. You start out with the familiar {{#switch:{{{1|}}} but that is where the similarities stop. The rest is more similar in syntax to a complex parameter template. Hopefully it will be self explanatory.
This user likes the wiki because of {{#switch:{{{1|}}}|1 = the clan chat |2 = the free cookies |3 = the free information}}.

This means that if the first parameter is only defined as 1, 2, or 3 when it is being used, it will switch to be whatever the template itself defines those options to be.

defaults

These, however, are quite simple. If you want a certain parameter to be optional and default to something when it is not defined in use, the syntax would be {{{parameter name|default option}}}.

Includeonly, noinclude and onlyinclude tags

These two brackets are used in situations when you want some things on the template page to be excluded from the actual template or when you do not want it to be part of the template page.

Includeonly

Adding <includeonly></includeonly> around a section of text will cause it to only appear as part of the template. This is especially useful when adding a category to the template that you do not want the template to be a part of.

Noinclude

This will do the exact opposite. If you add <noinclude></noinclude> around a section of text, it will not be part of the template. This is mainly used for documentation purposes (documentation being the instructions as to how to use the template), which we do not want to be included in the template.

Onlyinclude

Adding <onlyinclude></onlyinclude> around a section of code will make that section the only section to be used in the template. This is equivalent to using noinclude around the every other part of the text, e.g.

I like the <onlyinclude>RuneScape</onlyinclude> Wiki

will give the same effect as

<noinclude>I like the</noinclude>RuneScape<noinclude> Wiki</noinclude>

except the onlyinclude version uses less raw text, and is often easier to follow. This tag has less applications than the other two, but is useful in certain situations.

Using Documentation

Instructions as to how to use each template should be found in a documentation section of the template page. With your knowledge of how to use templates, it should be easy to figure out. If there is no documentation or you still have questions about the template, contact another user or the creator of the template.

Namespaces

As touched on in the previous lesson, Wikis have a series of Namespaces. These are a sort of category for a certain type of page. Each one can be used as a template, though each behaves differently when used as such.

Namespace Template/Link Title Notes
Mainspace : This is the namespace for actual articles. If you look up an article, it is in the main namespace, or the "Mainspace". When used as a template, which will simply cause the content of the page to appear wherever you put it. It has no true namespace title, but requires a Colon be put in front of it when being used as a template (but not as a link) Example: {{:Armour}}
Talkspace Talk: This is a discussion page for each article. This is where community members can make notes about the article itself and discuss larger changes to it. All namespaces have a talk page to go with it unless otherwise noted, so assume that there is one if not listed.
Userspace User: This is the namespace for userpages. Every user has one that they may customize at their leisure. Any personal pages are sub-pages of a user's Userpage.
User talkspace User talk: This is where you can leave messages for another user. The user will receive alerts when their talk page is edited.
Project RuneScape: These are sort of miscellaneous pages that don't fit into any other category. They are generally administrative in nature or for community purposes as opposed to Runescape information. This page itself is within this namespace, and the name of the Projectspace varies from wiki to wiki.
Filespace File: These are pages that host images and other files and generally display information about them. If one were to link to it via a wiki-link, it would display the image or file rather than a link to it, which would require the syntax "[[:File:filename.png]]", the extra colon in front causing it to become a wiki-link.
Forumspace Forum: These are for discussion pages about larger changes to the wiki as opposed to individual articles. It is one of the two namespaces that does not have a talk page as it is already for discussion in and of itself. (Note: the Forum talk: namespace does actually exist, but is not used, except by users who for some reason cannot edit the main forum page.)
Category Category: These are pages that display all the pages in a particular category, or group of pages. If one were to add a wiki-link to it, it would add the page to that category instead of display the link. In order to add a link to the category page itself, one would follow similar syntax to the filespace wiki-link.
Updatespace Update: These pages contain content written by Jagex about each individual update. They are kept for historical and reference purpose, and thus are kept in its own namespace.
Exchangespace Exchange: These pages contain data from the Grand Exchange Database that are updated by bots. This controls how prices appear on other pages so that one does not have to go to each individual page a price appears to change it.
MediaWiki MediaWiki: These pages control the software for the website, and thus can only be edited by administrators.
Template Template: This namespace is set aside for the purpose of templates. When using as a template, it does not require that "Template:" be written in front of it as it is assumed, though this does not apply when one is linking to it.
Special Special: Pages in the Special namespace are just that: special. They are used for many things including preferences, logging in, maintenance, and generally for things that a standard content page cannot do because of software limitations. Special pages are the other namespace that do not have any talk pages. Some examples include: Special:Upload is for uploading images to the wiki; Special:RecentChanges shows a chronological list of recent edits and actions to the wiki; Special:Preferences allows changing of editing settings; Special:Block allows administrators to prevents users from editing. A full list of special pages can be found at Special:SpecialPages.
Community content is available under CC-BY-SA unless otherwise noted.