Help:Templates

From Wikipedia of the Dark Brotherhood, an online Star Wars Club
Help:Contents

This article is meant to clarify basic template use. This is NOT a tutorial for actually writing templates. Those seeking information about designing templates will find links to relevant information in the External links section.

What are templates?

Templates are segments of wiki markup that are stored in one central location (the Template namespace) so that they can be used repeatedly. They are made up of Wikitext, HTML, and CSS markup just like every other page on DJBWiki.

Template calls

Templates are added to a page through the use of template calls. When a template call is inserted into a page, it tells the MediaWiki software to dynamically transclude (insert) the relevant template into the source code of that page every time that the server sends it to be viewed in a browser.

Syntax

{{template name|parameter1|parameter2|…}}

A template call consists of the template's name followed by any included science) parameters. The parameters are delimited by a pipe ("|") symbol and the entire template invocation is then surrounded by double curly brackets ("{{…}}").

Example


"{{{1}}}"
―{{{2}}}

Within the source code of a template, variables are surrounded with three curly brackets ("{{{variable}}}"). If they are not assigned a value through the use of template call parameters, displayed variables will appear just as they are defined. For instance, the Quote template displays its first two unnamed variables, {{{1}}} and {{{2}}}, if it is invoked without parameters.

Such behavior can be overridden by tweaking the template involved using default parameters and/or ParserFunctions, but such topics are beyond the limited scope of this help page.

Wiki markup

{{Quote}}

The template call above invokes the Quote template.

Variables

Many templates can be customized, to some degree, by adding parameters to the template call. Template parameters are used to assign values to variables that have been built into the template's code. Template variables come in two distinct flavors: named and unnamed.

Unnamed variables

Writing a template call for a template that makes use of unnamed variables can be tricky because it requires the editor to know quite a lot about the internal workings of the template that they intend to use. Within the template's source code, unnamed variables are referenced using numbers rather than names. Their number corresponds to their position in the parameter list of the template call. You can assign values to unnamed variables in one of two ways:

{{template name|variable 1 value|variable 2 value|…}}
{{template name|1=variable 1 value|2=variable 2 value|…}}

Example


"Hello world!"
―anonymous
Wiki markup
{{Quote|Hello world!|anonymous}}
{{Quote|1=Hello world!|2=anonymous}}
{{Quote|2=anonymous|1=Hello world!}}

Named variables

Named variables can only be assigned a value by adding the variable's name to the parameter list of the template call and explicitly assigning it a value through the use of an equals ("=") operator.

Notes

  1. It does not matter what order you list named parameters in.
  2. If we substituted {{Currentevents|black}}, the superfluous parameter would be ignored and the template would appear as normal.
  3. If a single variable is assigned a value twice within a template call, the second value assignment (right to left) will supersede the first.
    Thus {{Currentevents|BG1=black|BG=white}} produces a background color of 'white', not 'black'.

Common mistakes

Confusing template calls with wiki tables

Many new editors confuse template calls with wiki tables. It is important to understand that the two constructs are in no way connected even though they use a similar syntax. Wiki tables are merely a simplification of HTML tables which are used to provide structure for content.

Wiki table sytax

{|
|+ table caption
|-
! table heading
|-
| table cell
|-
| table cell (next row)
| table cell (same row)
|}

Whitespace

Wiki markup does not always ignore whitespace. Therefore, it is important to keep your source code as condensed as possible. The MediaWiki software generally does not respect whitespace unless the user adds excess carriage returns, but implementation is uneven.

Template calls that involve named variables can be written in numerous ways without any adverse effects:

{{Character|type = Sith|image=[[image:WinGallusWiki.jpg|250px]]|name= Windos Helkin Tarentae|homeworld=Coruscant}}

Can also be written as:

{{Character
|type = Sith
|image=[[image:WinGallusWiki.jpg|250px]]
|name= Windos Helkin Tarentae
|homeworld=Coruscant
}}

And the output will not be affected:

Windos Helkin Tarentae
Biographical Information
Homeworld:

Coruscant

Physical Description
Personal Information
Chronology & Political Information
[ Source ]



But when dealing with unnamed variables, one must use more caution. For instance:

{{Quote|Hello world!|anonymous}}

Rewritten as:

{{Quote
|Hello world!
|anonymous
}}

Produces this mess:


"Hello world!

"

―anonymous

If you simply must structure your template calls that way, you can rewrite it like this:

{{Quote
|1=Hello world!
|2=anonymous
}}

And it works just fine:


"Hello world!"
―anonymous

Incorrect template calls

It is best not to include extra pipe ("|") symbols in template calls. Usually they are harmless, but if the template you are calling has one or more unnamed variables, you will inadvertently be assigning it a value of "" (ie. NOTHING), which can break the template.

Examples

{{|
template name
|variable name=value
|}}

The example above is a common result of confusing template calls with wiki tables.

{{template name|
|variable name=value|
}}

Only one pipe symbol should delimit template call parameters.

Correct template calls

Templates calls can be written in any of the following ways. The preferred structuring varies from wiki to wiki.

{{template name
|variable name=value
}}

{{template name|
variable name=value
}}

{{template name|
variable name=value}}

{{template name
|variable name=value}}

{{template name|variable name=value}}

External links

Wikimedia Meta-Wiki

Mediawiki

Misc.