Wikia

WoWWiki

Help:Template

Talk28
101,311pages on
this wiki

Redirected from WoWWiki:Template

HELP CONTENTS · Getting Started · New to WoWWIKI · Editing WoWWIKI · Editing WoWWIKI (advanced)
The WoWWIKI Community · Additional Help · Mists-Logo-Small Updating for Mists of Pandaria
See Wikia Help for general Wikia- and wiki- related help. See Metawiki logo 18x18  Meta-Wiki HelpIntro for basic MediaWiki usage!

This page is meant to be a quick how-to with helpful tips for creating and editing templates in WoWWiki. It is not meant as a definitive tech reference. MediaWiki's own page has that already.

"Template:" vs Local Templates Edit

You may already have seen that some pages use {{Sometemplate}} while others use {{Template:Sometemplate}}. This usually means the same thing; if you don't tell the wiki in which namespace to look, it will look under "Template:".

Wait, what did I just say?

  • A template does not have to live under "Template:". You can pull in a page from wherever into your page.

For site-wide templates, it makes sense to put them in the "Template:" namespace where everyone can find them, but for something that you're only using in a few pages, it makes much more sense to just put it in e.g. "MyPage/TheTemplate", and pull it in with {{:MyPage/TheTemplate}}.

  • Note the ":" at the beginning of {{:MyPage/....   Since most pages live in the "main" namespace of the wiki, we'd not be telling the wiki where to look for the page to include, so it'd go look in "Template:", where it wouldn't find much.   ":" by itself means "Look in the main namespace, please".

You will have to use your own judgement for what's right for your template. Here's a few instructive examples though:

Templates that belong in "Template:" Edit

Naming your template Edit

This depends on where your template gets placed, really. And how commonly used you think it's going to be.

  • Used dozens of times?
- Pick a short name.
  • Used a handful of times?
- Long, descriptive name.
  • In "Template:", a very commonly used template will likely be a single word, or two contracted words, all in lowercase. This makes it fast and easy to write. Examples include: {{clr}}, {{infoline}}, ... For instance, "WoW API" should probably have been named simply "wowapi" -- much easier to write often.
  • "Template:" templates that are more seldomly used will need a more descriptive name. But its name will still be fairly short.
  • A locally stored template will typically be a subpage of something else, e.g. "My Page/My Template". Other than that, it can have just about any name.
    • If it needs to be long winded and descriptive, make it so: {{WoWWiki:Policy/Terminating/Direct termination terms}} (but you'll still go nuts if you need to include it in more than a handful of pages).
    • Or be more brief; as long as you think people understand what the template is about when they stumble over it.

Explaining what your template does Edit

It's very helpful to others (or, heck, yourself half a year from now!) to explain what your template actually does and why it exists. It's easy to put this information in the template without it pestering pages where it's included:

<noinclude>''This template does X and is used by Y. I made it a template because Z. --~~~~''

</noinclude>
(and then the actual template...)

... where "X" and "Z" certainly can be left out if it's obvious, and "Y" might be "globally" or "all pages dealing with ...". It doesn't even have to follow any particular format, really; just a quick note about the template helps!

This becomes even more important when your template uses parameters. Other people really appreciate it when you explain what order to input things.

Templates have Talk pages too! Edit

If there's more you'd like to say about your template than you care to explain between <noinclude> tags, templates do have talk pages just like any other page! It might be a good idea to mention that there's info in the talk page between your <noinclude> tags though; most people don't go looking for talks on templates. ;-)

Tips and tricks Edit

Categories in templates Edit

If you put a category in a template, all pages that use the template will suddenly end up in that category. Well, semi-suddenly anyway; the page needs to be edited once (just add a blank line or a space) before they're actually moved.

However, if you just go ahead and put in the category tag, your template will end up in the category too, which is maybe not what you intended. Use this:

<includeonly>[[Category:MyCategory]]</includeonly>

Template parameters Edit

This is actually a fairly huge topic; we'll try to cut it short.

MyTemplate: {{{1}}}, look! My template uses {{{2}}}!
Using it: {{MyTemplate|Mommy|parameters}}
Results in: Mommy, look! My template uses parameters!

You can also name parameters:

MyTemplate: {{{who}}}, look! My template uses {{{something}}}!
Using it: {{MyTemplate|something=parameters|who=Mommy}}
Results in: Mommy, look! My template uses parameters!

You can also give default values for things that aren't supplied:

MyTemplate: {{{who|Oi}}}, look! My template uses {{{something|parameters}}}!
Using it: {{MyTemplate|something=parameter defaults!!}}
Results in: Oi, look! My template uses parameter defaults!!!

Equal signs in parameter values Edit

Since equal signs, "=", are part of how parameter values are supplied, they're a little bit troublesome. You can't supply equal signs to numbered parameters at all. However, you can supply them to named parameters:

{{MyTemplate|Haha =)}}

This will probably not work like you intended. You're setting the parameter "Haha" to ")". Not "1" to "Haha =)".

{{MyTemplate|text=Haha =)}}

This example sets the parameter "text" to "Haha =)".

Templates can use templates! Edit

When your templates are getting big, chances are you want to re-use something from one template in another template.

  • Just cut the common parts out and paste them into a new template and then use that template in other templates!

There's also other reasons why you may want to use sub-templates. See e.g. {{Delete}} and {{Delete/Content}}. Pulling in "Delete" automatically marks the page for deletion, but WoWWiki:Delete also wants to show what it looks like without getting itself marked for deletion, so it just pulls in "Delete/Content".

Splitting templates into a /Begin and /End Edit

  • For an example of split templates, see {{Example/Begin}} and {{Example/End}}.
  • Of course, {{Example}} pulls them both in for places where you don't need the extra oomph.

Template parameters can't contain just anything. They're pretty aggressive about HTML tags, and trying to insert "{" or "}" or "=" is bordering on painful. So for templates where you know you'll have lots of content, or quirky content, it makes more sense to split them up into a "Begin" and "End" template, e.g. "MyTemplate/Begin", "MyTemplate/End".

  • Note: You cannot begin a HTML tag in one template and end it in another. The MediaWiki software refuses to leave HTML tags unfinished in a page, so it helpfully ends them for you right at the end of the "Begin" snippet, long before they're of any use to you.
MyTemplate/Begin: <table ...><tr>
MyTemplate/End: </tr></table>
« This won't work!
  • Wiki-style tables, on the other hand, can be begun in one template and ended in another.
MyTemplate/Begin: {| ...
MyTemplate/End: |}
« This will work!

Categorize your templates! Edit

It helps other editors (and probably yourself, too!) if you categorize your templates themselves. Perhaps not so much for "Template:" templates, but definitely for local templates!

Pages that use a local template will likely share one or more common categories, so making a "Your Category/Templates" and putting the templates there helps other editors find them easily!

Example:
  • Make sure that pages using your template don't end up in the "/Templates" category!
<noinclude>This template does X and is used by Y. See the talk page!  --~~~~
[[Category: My Category/Templates]] </noinclude>
(and then the actual template...)

Automatic subtemplate selection Edit

There is a number of built-in variables that are very useful for templates.

One such is {{PAGENAME}}, which for this page is "Template". So all base zone pages could for instance use a template that pulls in ":{{PAGENAME}}/Boss list", and links to "{{PAGENAME}}/Loot list". But attempting to use that template inside one of the subpages would break horribly.

Pages with lots of templates not updating Edit

When a page pulls in lots of templates, it won't always update when a template changes. There are two ways to force a refresh:

  • Do a dummy edit on the page
  • Do "action=purge" on the page, e.g. http://www.wowwiki.com/Help:Template?action=purge
    • The {{purge|<your text>}} template creates such a link in the page itself.
Icon-information-22x22 This problem should be alleviated as of the MediaWiki 1.7 upgrade (which happened in September 2006). The wiki software will attempt to update many of the pages using the template immediately, but if there's too many to do immediately, it'll spread the work over the next few minutes.

Is anything on this page unclear? Or is there something you'd like to know more about? - Drop a line in the Talk page!

See also Edit

  • Category:Templates. Nearly everything in the "Template:" namespace, categorized in subcategories.

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