Help:Templates

This is 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 code that are stored in one central location so that they can be used repeatedly. They are made up of Wiki markup, HTML, and CSS markup just like every other page on Wookieepedia. In fact, templates are no different from any other page except that they are usually stored in the Template namespace.

Template calls
When a template call is inserted into a page, it tells the MediaWiki software to dynamically substitute the code stored in the template into that page every time that the server sends the data to be rendered in a browser.

Syntax
A template call consists of the template's name followed by any included parameters, all of which are delimited by a pipe ("|") symbol. The entire template invocation is then surrounded by double curly brackets ("&#123;&#123;&hellip;&#125;&#125;").

Code:
The code above invokes the Quote template.
 * Note that including the template namespace in the template call is optional and that the first letter of the template's title is not case sensitive. could be substituted for the code above and it would work exactly the same.
 * Note that any normal wiki page can be used as a template and dynamically inserted into another page by using the syntax:
 * Note that the template looks strange in the example above because the quote template was built to expect the user to assign values to its unnamed variables though the use of template call parameters. We will discuss how to do that next&hellip;

Variables
Many templates can be customized, to some degree, by adding parameters into 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 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:

OR

Example:
"Hello world!"

- anonymous

Code:
OR

OR

The template calls above assign values to the first and second unnamed variables contained in the quote template.
 * Note that in the third template call, the variable assignments are reversed. Using the syntax presented in the second and third code examples, you can list parameters in whatever order you wish. BUT, Parameter order is vitally important when using the syntax that is presented in the first code example. If the parameters are listed out of order, in that case, the template will likely be broken or become seriously distorted (but happily the Quote template handles the abuse gracefully):

Is the equivalent of:

They both produce this nonsensical statement: "anonymous"

- Hello world!


 * Note that if you use the second method of unnamed variable assignment, the template call behavior is exactly the same as that for named variables, which we will discuss next&hellip;

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

Code:
The template call above includes a parameter that assigns a color value to the C1 variable of the Jedi Civil War campaign template. Thus produces a background color of 'white', not 'black'.
 * Note that it does not matter what order you list named parameters in.
 * Note that if we substituted, the superfluous parameter would be ignored and the template would appear as normal.
 * Note also that if a single variable is assigned a value twice within a template call, the second value assignment (right to left) will supersede the first.

Whitespace
Unlike SGML derived languages such as HTML and XML, Wiki markup does not always ignore whitespace (ie. space and control characters). 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&hellip;

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

Can also be written as:

And the output will not be affected:

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

Rewritten as:

Produces this mess: "Hello world!"

- anonymous

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

And it works just fine: "Hello world!"

Template calls are not 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 just a simplified form of HTML tables which are quite unremarkable.

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 uninitialized, unnamed variabls, you will inadvertantly be assigning it a value of "" (ie. NOTHING), which can break the template.

Wikimedia Meta-Wiki

 * Help:A quick guide to templates
 * Help:Template
 * Help:Advanced templates
 * Help:Template documentation
 * Help:HTML in wikitext
 * Help:Variable
 * Help:Magic words
 * Help:Parameter default
 * Help:Namespace
 * Help:Substitution
 * Help:Colon function
 * ParserFunctions

Mediawiki

 * Help:Templates

Misc.

 * Learn HTML
 * Learn CSS