Jump to content

Help:Templates: Difference between revisions

From SeptemWiki
No edit summary
No edit summary
Line 1: Line 1:
'''Templates''' are pages which can be included inside other pages by using the <code><nowiki>{{ }}</nowiki></code> syntax.
'''Templates''' are pages which can be included inside other pages by using the <code><nowiki>{{ }}</nowiki></code> Wiki syntax.


== How the syntax works ==
== What a Template Does ==


At a basic level, if you put <code><nowiki>{{Namespace:Page}}</nowiki></code> into your page, then at that point, the contents of the page <code>Namespace:Page</code> will be included, regardless of the page.
In essence, a template is a small piece of Wiki text, tables, or whatever that you want to include repeatedly in other pages.


For pages that are generally ''intended'' to be used as templates, if you put them in the <code>Template:</code> namespace, then you don't need to specify the namespace when using the curly braces, because that's what it assumes by default.
A template can be as simple as you like; if we create a page called <code>Template:Jerkface</code> and it just contains "Shawn Knight", then every place we put <code><nowiki>{{Jerkface}}</nowiki></code> in the wiki, "Shawn Knight" will appear.  But then simply by editing <code>Template:Jerkface</code> to say "Alan Caum", every page which uses the template will show Alan's name instead. This allows numerous articles to refer to whoever the current jerkface is, without having to edit them all when that changes; instead, we just edit the template.


A template can be as simple as you like; if I create a page called <code>Template:Jerkface</code> and it just contains "Shawn Knight", then every place we put <code><nowiki>{{Jerkface}}</nowiki></code> in the wiki, "Shawn Knight" will appear.  But then simply by editing <code>Template:Jerkface</code> to say "Alan Caum", every page which uses the template will show Alan's name instead.
== Template Syntax ==


== Templates with Parameters ==
A template is inserted into a page using the syntax:


{{PlazaBox|county=Fulton|caption=Actually there is no plaza named Template Demo, that would be a silly name; this is Sideling Hill Plaza.|name=Sideling Hill|image=[[File:Sideling_Hill_Plaza.jpg|200px]]|direction=Eastbound and Westbound|state=Kalmont}}
<nowiki>{{TemplateName|param1=A|param2=B|param3=C|...}}</nowiki>


At a more advanced level, a template can have parameters, separated inside the curly braces by vertical bars.  And generally a parameter has both a name and a value, connected by an equal sign.
where <tt>TemplateName</tt> is the name of the template, and <tt>param1</tt> is the name of a parameter given the value <tt>A</tt>, <tt>param2</tt> is a parameter given the value <tt>B</tt>, and so on.


Here's an example of an info box for a service plaza, using the <code>PlazaBox</code> template, with a number of parameters.
In the event you wish to make your wiki code more readable, you may insert line breaks between the parameters of a template.  So the example at the top of this section could be written:


And the syntax which produces this can be written all in one line:
<nowiki>{{TemplateName
|param1=A
|param2=B
|param3=C
|...}}</nowiki>


<nowiki>{{PlazaBox|county=Fulton|caption=Actually there is no plaza named Template Demo, that would be a silly name; this is Sideling Hill Plaza.|name=Sideling Hill|image=[[File:Sideling_Hill_Plaza.jpg|200px]]|direction=Eastbound and Westbound|state=Kalmont}}</nowiki>
Here's a real example of a template being used with a bunch of parameters:
 
Or broken down with each parameter on a line for readability:


  <nowiki>{{PlazaBox
  <nowiki>{{PlazaBox
Line 31: Line 33:
|state=Kalmont}}</nowiki>
|state=Kalmont}}</nowiki>


Notice that the names of the parameters do not appear in our syntax in the order they get used in the production of the template.  Since they have names, we don't need to remember the correct order to put them in.  We just have to know what the template allows us to use.  Which is a matter of the template being well-documented.
{{PlazaBox
|county=Fulton
|caption=Actually there is no plaza named Template Demo, that would be a silly name; this is Sideling Hill Plaza.
|name=Template Demo
|image=[[File:Sideling_Hill_Plaza.jpg|200px]]
|direction=Eastbound and Westbound
|state=Kalmont}}
 
And it would generate the info box you see to the right here, with the picture and caption and all that.
 
In this particular template, we don't need to know the order to put the parameters in, because each parameter has a name.


{{Clear}}
{{Clear}}
For some simple templates, only parameter values are specified, not their names; if there are multiple parameters in such a case, they must be given in order.  An example is the "main article" template, which takes only one parameter:
<nowiki>{{main|Triparic language}}</nowiki>
And some templates may be so simple they need no parameters at all:
<nowiki>{{stub}}</nowiki>


== Template Documentation ==
== Template Documentation ==

Revision as of 12:11, 9 April 2016

Templates are pages which can be included inside other pages by using the {{ }} Wiki syntax.

What a Template Does

In essence, a template is a small piece of Wiki text, tables, or whatever that you want to include repeatedly in other pages.

A template can be as simple as you like; if we create a page called Template:Jerkface and it just contains "Shawn Knight", then every place we put {{Jerkface}} in the wiki, "Shawn Knight" will appear. But then simply by editing Template:Jerkface to say "Alan Caum", every page which uses the template will show Alan's name instead. This allows numerous articles to refer to whoever the current jerkface is, without having to edit them all when that changes; instead, we just edit the template.

Template Syntax

A template is inserted into a page using the syntax:

{{TemplateName|param1=A|param2=B|param3=C|...}}

where TemplateName is the name of the template, and param1 is the name of a parameter given the value A, param2 is a parameter given the value B, and so on.

In the event you wish to make your wiki code more readable, you may insert line breaks between the parameters of a template. So the example at the top of this section could be written:

{{TemplateName
|param1=A
|param2=B
|param3=C
|...}}

Here's a real example of a template being used with a bunch of parameters:

{{PlazaBox
|county=Fulton
|caption=Actually there is no plaza named Template Demo, that would be a silly name; this is Sideling Hill Plaza.
|name=Template Demo
|image=[[File:Sideling_Hill_Plaza.jpg|200px]]
|direction=Eastbound and Westbound
|state=Kalmont}}
Template Demo Service Plaza

Actually there is no plaza named Template Demo, that would be a silly name; this is Sideling Hill Plaza.
Direction Eastbound and Westbound
County Fulton
State Kalmont


And it would generate the info box you see to the right here, with the picture and caption and all that.

In this particular template, we don't need to know the order to put the parameters in, because each parameter has a name.

For some simple templates, only parameter values are specified, not their names; if there are multiple parameters in such a case, they must be given in order. An example is the "main article" template, which takes only one parameter:

{{main|Triparic language}}

And some templates may be so simple they need no parameters at all:

{{stub}}

Template Documentation

Here at SeptemWiki, we're trying to ensure that each template is well-documented. When you visit the template's page directly, like Template:PlazaBox, you should see some decent documentation on what the parameters are (if any) and how to put the template in your page.

Editing Templates

Not everyone with permission to edit an article has permission to edit templates, because you have the potential to break a lot of pages if you screw one up. If you need a template for something, either ask Shawn to do it or show him that you're really comfortable with the syntax.

All Template Pages