Wikia

Wookieepedia

Help:Templates

Talk0
111,638pages on
this wiki
Revision as of 11:32, May 31, 2011 by Cavalier One (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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?Edit

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 Wookieepedia.

Template callsEdit

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.

SyntaxEdit

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

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

ExampleEdit

"{{{1}}}"
―{{{2}}}
[1]

Wiki markupEdit

{{quote}}

The template call above invokes the Quote template.

NotesEdit

  1. Inclusion of the template namespace in the template call is optional and the first letter of the template's title is not case sensitive. The output of {{Template:Quote}} is the same as {{quote}}.
  2. Any wiki page can be used as a template and dynamically inserted into another page by using the syntax: {{namespace:page name}}. Pages in the main namespace use the unique syntax: {{:page name}}.
  3. The template looks strange in the example above because the quote template was constructed to expect the user to assign values to its unnamed variables through the use of template call parameters. We will discuss how to do that next.

VariablesEdit

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.

Important note:
Template variables should not be confused with predefined MediaWiki variables (see Help:Variable). [2]

Unnamed variablesEdit

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|…}}

ExampleEdit

"Hello world!"
―anonymous
Wiki markupEdit
{{quote|Hello world!|anonymous}}
{{quote|1=Hello world!|2=anonymous}}
{{quote|2=anonymous|1=Hello world!}}

NotesEdit

All of 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):

{{quote|anonymous|Hello world!}}

Is the equivalent of:

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

They both produce this nonsensical statement:

"anonymous"
―Hello world!

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.

Named variablesEdit

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.

NotesEdit

  1. It does not matter what order you list named parameters in.
  2. If we substituted {{Jedi Civil War|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 {{Jedi Civil War|c1=black|c1=white}} produces a background color of 'white', not 'black'.

Common mistakesEdit

Confusing template calls with wiki tablesEdit

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 sytaxEdit

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

WhitespaceEdit

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:

{{Hyperspace|url=fiction/f20080423/index.html|text=Precipice|int=Precipice}}

Can also be written as:

{{Hyperspace
|url=fiction/f20080423/index.html
|text=Precipice
|int=Precipice
}}

And the output will not be affected:

HyperspaceIconPrecipice on Hyperspace (article) (content now obsolete and unavailable)


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 callsEdit

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.

ExamplesEdit

{{|
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 callsEdit

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}}

Template modifiersEdit

Special modifiers can be added to a template call in order to change the way that the MediaWiki software handles it. Modifiers are added to a template call using the following syntax:

{{modifier:Template name}}
Usage Explanation
{{int:xyz}} Shorthand for {{MediaWiki:xyz}}, it is rendered as <xyz> if the page MediaWiki:xyz does not exist.
{{msg:xyz}} The "msg" modifier forces the use of {{Template:xyz}} unless the template doesn't exist. It is useful in the rare case that a template and a MediaWiki predefined variable (see Help:Variable) are both named "xyz". Normally, MediaWiki variables have priority when there is a conflict.
{{msgnw:xyz}} The unevaluated wikitext is rendered. See Help:Template#msgnw.
{{raw:xyz}} Equivalent to {{msg:xyz}} above.
{{subst:xyz}} In the wikitext, the tag is substituted by the content (single-level evaluation only), see Help:Substitution.

The most commonly used modifier is "subst" which substitutes the raw source code generated by the template call for the template call itself, once the page is saved. It should be noted that it is possible to preview what the generated code will look like by using the the diff ("Show changes") preview page.

Substitution should be used sparingly as it introduces ugly and often confusing code into a wiki page. Perhaps more importantly, once substituted, the generated wikitext ceases to be a template and therefore it can no longer be immediately updated when its source template is changed.

However, substitution does have some advantages. Substituted code places less strain upon the server and allows a page to load slightly faster. In addition, some templates may not function properly unless they are substituted.

FootnotesEdit

  1. 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.
  2. MediaWiki variables, sometimes called "Magic words" or "predefined templates", are special wiki objects that are referenced using the same syntax as templates. Calling them variables at all could be considered something of a misnomer as their value cannot be changed. In fact, it is more proper to call them functions (ie. Parser functions) which are exclusively used to retrieve information from the server.

See alsoEdit

External linksEdit

Wikimedia Meta-WikiEdit

MediawikiEdit

Misc.Edit

A template is a special type of page that has been designed so its content can be included in other pages. Since a given template can be included in many pages, it can help reduce duplication and promote a uniform style between pages.

Templates can be useful for...

  • Creating content that should appear on many pages.
  • Formatting content (such as infoboxes) in a way that should be consistent across many pages.
  • Creating a shortcut for writing things that you repeat often when communicating with others.
  • Replacing long, complicated code so that a page is easier for other users to edit.
  • Protecting parts of a page from editing while leaving other sections open for edits.

Templates are usually located in the Template namespace. This includes any page with a name beginning with Template:, such as Template:Name.

Video overview

If you're new to templates, this video will help you get started.

Introduction to Templates03:40

Introduction to Templates

How to create a basic template

Templates can be very powerful, but also sometimes very complicated. It often helps to start by creating the simplest possible kind of template, and then experimenting from there.

  • On your wikia, go to Template:Example and click "Create".
  • Type "Hello, World" in the editor.
  • Click "Publish". You have just created a template with some sample content.
  • On your wikia, create a new article called "Template test".
  • In the editor, go to source mode and enter the following code:
{{Example}}
  • Click Publish. Your "Testing Templates" page should display the text you added to your template.

You've successfully created and used a template! Now you can change the content of your template and add it to more pages to make it more useful for your community.

Adding pre-existing templates

Templates-rightrail

Wikias come with pre-loaded default templates. You can view a complete list of templates available on your wikia by going to Special:AllPages and selecting "Template" from the namespace dropdown menu. Click "Go" and all available templates will appear in a list.

  • In the editor's visual mode, you can select from the list of all templates available on your wikia by clicking "Add other templates".
  • In source mode, you can use the code {{Template name}} to add any template to your page.
  • Advanced users can edit the page MediaWiki:Editor-template-list to change the list of templates available by default in the "Templates" section of the editor. Up to four templates can be in this list.

Advanced templates

Template parameters

Templates can have parameters - these allow you to alter the way the template is displayed, such as including specific text or altering the design.

To take Template:Wikipedia as an example, adding just {{Wikipedia}} assumes that the page on Wikipedia is the same name as the page of the current page the template is used on. However, a parameter can be added, e.g. {{Wikipedia|Microsoft}}, to tell the template that the page on Wikipedia was Microsoft.

To learn more about how to change the output of the template based on what the user inputs, see Help:Template parameters and Help:Parser functions.

Substituting templates

A different way to use a template is to substitute its content into a page. This is done by inserting subst: immediately after the opening braces: {{subst:templatename}}. Once the page is saved, the link to the template is removed and the template output is substituted in its place and can be further edited. Any updates to the template will not affect the content that was substituted into the page.

To learn more, visit Help:Substituting templates.

Updating and adding standard templates

The official Starter Wiki and semi-official Templates Wiki occasionally improve some of their documentation as well as adding new templates specifically designed for Wikia sites, and are therefore worth checking from time to time.

Copying templates from other wikis

Contributors throughout Wikia have made all different kinds of templates. It is often simpler to copy an existing template and modify it for your needs, rather than creating one from scratch. The Templates Wiki is a good place to start looking for a template that fits your needs. In most cases, you are free to copy templates based on the shared CC-by-SA license, but make sure the wikia you want to copy from does not have an alternative licensing scheme that may place restrictions on what you can copy.

Here are some basic steps to copy most templates:

  1. Find the template you want to copy (usually http://wikiname.wikia.com/wiki/Template:templatename).
  2. Click the Edit button, select all of the wikitext and copy it.
  3. Create a new template page on your wikia (http://yourwiki.wikia.com/wiki/Template:templatename?action=edit).
  4. Paste the wikitext code you copied and press the Publish button.

Many templates have a separate subpage for documentation about the template. Fortunately, the location is often standardized, so it is easy to copy the documentation as well. If you notice the template page you copied above does not look like the original, it is likely the documentation is on a separate subpage:

  1. Find the template documentation you want to copy (usually http://wikiname.wikia.com/wiki/Template:templatename/doc).
  2. Click the Edit button, select all the wikitext and copy it.
  3. Create a new template documentation subpage page on your wikia (http://yourwiki.wikia.com/wiki/Template:templatename/doc?action=edit).
  4. Paste the wikitext code you copied and press the Publish button.

Template Webinar

Looking for further video instruction? This webinar recording overviews the basics of adding and customizing templates for your wikia.

Templates Overview25:30

Templates Overview

See also

Further help and feedback

Around Wikia's network

Random Wiki