Help:Templates
Contents |
Introduction
By now you may have established many of the more common wiki editing skills. In this guide you will be shown the top of the rabbit hole that is templates. (How deep does it go?)
Templates are mainly used to reduce effort where the contributor finds themself writing the same block of wiki code over and over again. They can also, as the name suggests, act to unify the appearance of a certain class of pages.
They also look a lot more tidy than the mass of code that they often replace.
Intrigued? Read on!
Template Basics
1.Creating a basic template
- Let's start with a simple example. Every time I write my name, I like to add my personal moniker next to it. To do this in wiki code would require me to type
http://proto.mindcloud.org/Helicopterbasic.jpg Tristan Miller
each and every time I wanted this:
Tristan Miller
to appear.
- At the very least this would require tedious copying and pasting all the time, or typing the same thing over and over.
- Instead, I'd like to make a template allowing me to get the same effect by just typing TJM. All I have to do is create a page called Template:TJM, and add the following to that page:
http://proto.mindcloud.org/Helicopterbasic.jpg Tristan Miller
2.Using the basic template
Now whenever I want my name and symbol to appear, in the page source I just write TJM inside a pair of double curly brackets:
{{TJM}},
and the effect is:
The beauty of this method is that any changes I make to the template effect all the pages that I've used it on. So if I decide my moniker is embarassing at some point, I won't have to pick my way through the wiki searching for all the pages I've used it on.
3.Creating a template with parameters
- More complicated templates can be constructed that allow for different parameters around the standard form.
- For instance, I could modify the previous template to allow anyone to insert their name and moniker on a page.
This is rather easy to do: instead of specifying the name and image URL in the template, I replace these values with parameters. It helps to give these parameters sensible names, so I'll call the name parameter Name, and the image parameter MonikerURL. In the template page source, each must be inside a pair of triple curly brackets, like so:
{{{MonikerURL}}} {{{Name}}}
This I put in a page named Template:MonName.
4.Using the template
When ready to use this new template, the magic words to enter in the page source are:
{{MonName|MonikerURL=http://proto.mindcloud.org/images/smallprotoMindcloud.png|Name=Arthur Pembleton}}
For the sake of tidiness, it is preferable to put a carriage return before each parameter:
{{MonName|
MonikerURL=http://proto.mindcloud.org/images/smallprotoMindcloud.png|
Name=Arthur Pembleton
}}
Either way, the result is:
Arthur Pembleton
In this case, it would actually be more effort to use the template. Of course this makes it useless, but the ability to slot in parameters can be applied to much more meaningful situations.
More advanced tips
- Formatting: all formatting applied in the template ends up applied in the pages in which it is used. This includes images, tables, html tags, links, anything! Drag in apparently incomprehensible HTML from the source code of other wikis, and turn into a parameterised happy land of beautiful formatting!
- Template use within templates: Sometimes it is useful to use a template in the definition of another...
- Repeating parameters: you can repeat the same parameter in a template as well. Take Template:RSSFeed for example.
That's about all I can tell you about this useful feature. If you'd like to know more about templates, refer to this page for horrible amounts of information about the use of templates.