Help:Templates

From BeatlesWiki

Jump to: navigation, search

Contents

Let's work on a simple example. See the article about the events of 1957.

The code to produce such a page is

{{EventYear}}

<ask format="template" template="Event On Year" sort="RevDate">
[[RevDate:=+]]
[[Year:=1957]]
[[ShortDescr:=*]]
[[Month:=*]]
[[Day:=*]]
</ask>

{{Refresh}}

The first line {{EventYear}} calls a template named EventYear.
The purpose of a template is to re-use pre-formatted text.
To call a template you must enclose it between {{ }}. That is 2 opening { and two closing } The template code itself is located in an article named Template:EventYear.

A very simple template

Before we go into the details of this template, let's see an even simpler template: Template:John.
The code of this template is the following

[[John Lennon|John]]

What this code does is create a link to an article called John Lennon using the text John. It looks like this: John.

Because I don't want to type [[John Lennon|John]] every time I want to link the text John to the article John Lennon, I've put this code into the Template:John and now I can simply call the template with this code

{{John}}

and it will produce the exact same result: John.
Let's say I have an article with the following code

Hello I'm [[John Lennon|John]], sometimes I play the fool

it could be rewritten with

Hello I'm {{John}}, sometimes I play the fool

Of course it's a very simple template and you might not yet see the advantages of using a template instead of wiki code.

A more complex template

Template:Taken from Wikipedia is used to display a message in a yellow box at the beginning of an article to warn the visitor that the article was taken (in whole or partially) from Wikipedia and that it should be reworked. The code for this template is

{| style="background-color:#ffffcc;" cellpadding="20" cellspacing="0" border="1"
|''This article is taken from [http://www.wikipedia.org WikiPedia] 
(possible automated direct link [http://www.wikipedia.org/wiki/{{PAGENAMEE}} here]).
<br>Although it's a good start, it should be reworked ASAP.''
|}

It would make no sense for you to type this code at the beginning of every article taken from wikipedia. Calling the template is much easier.
Also, if tomorrow it is decided to change the color of the box to red then only modifying the template is enough to have an effect on all the pages calling the template.

Template:EventYear

Back to our 1957 code. The code for Template:EventYear is the following

This is a list of events that occured in [[{{PAGENAME}}]]

{{PAGENAME}} is a Wiki variable used to display the name of the current page. If you place {{PAGENAME}} on an article titled The Long And Winding Road, it will display The Long And Winding Road. Using {{PAGENAME}} on the current help page you're reading will display: Templates.

In Template:EventYear, {{PAGENAME}} will display the name of the page where the template was called.
That's why, in the page 1957, the following text is displayed:

This is a list of events that occured in 1957

Template parameters

One of the interesting features of templates is that you can send parameters while calling the template. Depending on how the template was coded you may use unnamed parameters or named parameters.

Unnamed parameters

Template:Event On Day is used with Semantic Wiki to display an event that occured on a particular day of the year. For the purpose of this tutorial, I've slightly modified the original code to

* {{{2}}} <small>(see [[{{{1}}}]])</small>

An example call would be:

{{Event On Day
|Wonderwall premiere
|Wonderwall premiere in Cannes. George, Ringo, Pattie and Maureen attend
}}

It would produce:

  • Wonderwall premiere in Cannes. George, Ringo, Pattie and Maureen attend (see Wonderwall premiere)

We use the pipe symbol "|" to separate the parameters. The first parameter is Wonderwall premiere while the second is Wonderwall premiere in Cannes. George, Ringo, Pattie and Maureen attend.

When calling the template, the Wiki engine will replace

  • {{{1}}} with the value of the first parameter (Wonderwall premiere)
  • {{{2}}} with the value of the 2nd parameter (Wonderwall premiere in Cannes. George, Ringo, Pattie and Maureen attend)

so the equivalent code would be

* Wonderwall premiere in Cannes. George, Ringo, Pattie and Maureen attend <small>(see [[Wonderwall premiere]])</small>

Another example:

{{Event On Day
|Woolton Fete
|The [[Quarrymen]] play [[Putting On The Style]] at the [[Woolton]] fete
}}

will display:

Template:Rating-5 is used to display ratings on a 5-stars system. It takes on unnamed parameter defining the number of stars to display.

{{Rating-5|3}}

will display 3/5 stars

Named parameters

When there are too many parameters, it's easier to use named parameters. But the template must allow it. Let's modify the template Event On Day:

* {{{Event}}} <small>(see [[{{{Page}}}]])</small>

Calling it with the following code

{{Event On Day
|Page = Wonderwall premiere
|Event = Wonderwall premiere in Cannes. George, Ringo, Pattie and Maureen attend
}}

would produce

  • Wonderwall premiere in Cannes. George, Ringo, Pattie and Maureen attend (see Wonderwall premiere)

A more complex example is Template:Infobox Single, it is used to display a box on the side of an article with all kind of information about a particular single. It's syntax is:

{{Infobox Single 
| Name           = 
| Cover          = 
| Caption        = 
| Artist         = 
| from Album     = 
| A-side         = 
| B-side         = 
| Released       = 
| Format         = 
| Recorded       = 
| Genre          = 
| Length         = mm:ss
| Label          = 
| Writer         = 
| Producer       = 
| Certification  = 
| Chart position = 
| Last single    = 
| This single    = 
| Next single    = 
| Misc           =
}}

As you can see, it's a good thing that the template uses named parameters. For more details about this template, simply visit Template:Infobox Single.

Personal tools