FANDOM


Fantendo Help Logo (Tutorials)

Basics

A template is any page in the namespace "Template:". Pages in this namespace have special properties. For example, if one uses two braces ({{) with the template name, followed by closing braces (}}), a template has been added to the page. For example, if you wanted to add the construction template to a page, you would add
{{construction}}
to it. This works for any template on this wiki.

Creating templates

To create templates, all that needs to be done is to create a page titled Template:name here. It can be linked to as would be done with any page. To include information in the template that is for a purpose such as describing usage or categorizing it, <noinclude> content </noinclude> should be added to the templates so that is not added whenever the template is used on a page.

Parameters

The only templates you've learned to make so far, though, are static. This means that there is only one message that can go up. However, what if you want to make a table with a list of collaborators? This sounded complicated for me, as there was no content in this section when I wanted to learn, so I had to teach myself. However, now that I've made a section, learning will be simple!

In static templates, the text is always the same. Take this table, for example:

{| border="1" cellpadding="1" cellspacing="1" style="width: 100%; background-color: red; color: white; border: 1px solid white;"
|-
|'''Collaborator'''
|'''Role'''
|-
|InukaneYumiko
|Main creator
|-
|Sonic the Hedgehog
|Grammar editor
|}

It turns out to be like this:

Collaborator Role
InukaneYumiko Main creator
Sonic the Hedgehog Grammar editor

But if you want to make the second collaborator whatever the user wants it to be, that's where parameters come in. Parameters are variables that someone sets when they use the template, and appear as so visually. To make parameters, put the parameter name between {{{ and |}}}. For example, a parameter named "juice" would be created by typing {{{juice|}}}. Place the created variable wherever you want its value to appear. For example:

This is {{{juice|}}} juice.

However, parameters are useless without values. You assign a value to various variables in a template in the spot where you put the template. For example, if the above code with the juice parameter were in a template called "drink", we would declare it like this:

{{drink
|juice=apple
}}

This would result in the value "apple" being assigned to the parameter "juice". So, the template would display "This is apple juice." You've successfully used your first parameter!

You can also use multiple parameters in a template. Let's go back to the collaborators table. If the user wants to replace Sonic the Hedgehog and his role with something else, they can't do that. We can easily fix that, though, by creating parameters in place of the name and value.

{| border="1" cellpadding="1" cellspacing="1" style="width: 100%; background-color: red; color: white; border: 1px solid white;"
|-
|'''Collaborator'''
|'''Role'''
|-
|InukaneYumiko
|Main creator
|-
|{{{name|}}}
|{{{role|}}}
|}

Now, you'll have to assign values to both of the parameters when you use the template, which we will call "collaborator" for now:

{{collaborator
|name = Me
|role = Artist
}}

Now, the template will be displayed as this:

Collaborator Role
InukaneYumiko Main creator
Me Artist

The Users who use this template can now change the second user and his/her role! So, there you have it. You now know how to use parameters. Have fun with the new possibilities unlocked for you by this knowledge!

InukaneYumiko (talk) 17:27, June 16, 2014 (UTC)

Parser functions

#switch

Let's say you have a template, and you want to be able to switch between content using a single parameter. With wikicode, this is simple, due to parser functions. For this specific job, we need #switch. This demonstrates how to do it.

{{#switch:{{{parameter name}}}|#default=Content if parameter is not specified.|First value=Content if first value is specified}}

You can add as many values as you want. So for example, let's build a basic template. We want it to say WOMP. if it is not specified, but be able to switch to .PMOW using a parameter.

{{#switch:{{{1}}}|#default=WOMP.|1=.PMOW}}

If we add the template on a page without specifying a parameter, it will show WOMP.

{{template}}

If we made the first parameter equal to 1, it will show .PMOW.

{{template|1}}

#if

#ifeq

Useful templates

Fantendo Help Logo (Tutorials)
Some BasicsResizing an ImageEditing TablesMaking TemplatesUnderstanding the Skins
Community content is available under CC-BY-SA unless otherwise noted.