Simple Tip #3: Using Templates

by Andrew on March 12, 2009

in Editing Tips,RichmondWiki

MediaWiki templates are one of the most powerful editing tools in the software package. Unfortunately they are also one of the most confusing elements for new editors.

What is a Wiki Template?

Imagine that RichmondWiki has 100 articles for different businesses. We want each one to have the same basic visual layout for the name, address, and contact info. We could visit each article and manually enter the same markup (styling) for each. But that would require copying and pasting it 100 times and additional consistency maintenance problems if we decide to change it later.

Enter templates. We can create one template and “transclude” it in multiple articles. This means we only have to maintain one copy instead of 100.

In their simplest form, a template is simply a way to standardize the presentation of information. For example, the template for articles in the Businesses category looks like this:

Businesses Template

Businesses Template

To the tech-savvy, a template is basically a presentation layer that determines the visual layout of certain variables. It is mostly driven by CSS and parameters defined in the article that calls it.

To add this template to an article, you simply use this wikitext:

{{Business
|Name=Disco Sports
|AddressNumber=1400
|Street=Starling Drive
|City=Richmond
|State=VA
|Zip=23233
|Phone=(804) 285-4242
|WebAddress=http://www.discosports.com/
|County=Henrico
|YearEst=1970
}}

The {{ }} tell RichmondWiki that this is a template, specifically the “Business” template. Each of the variables (denoted by the | symbol) is defined in the Business Template itself, as well as the CSS-based presentation. This way we only have to change the Template file if we want to change the look and feel of every article that uses it.

How to Use Templates

Confused? Don’t be. We’ve created simple forms that allow you to take advantage of templates without ever having to touch the code (unless you want to!).

Use these forms to add a business, add a place of worship, add a nonprofit, or add a bar/restaurant and the template will automatically be filled in for you.

A full list of the templates in use in The RichmondWiki Project can be found on the Templates Special page.

But Wait, There’s More!

We also use templates to tell you if a page is a “Stub”, meaning it’s not complete and could benefit from some TLC. In that case, we call the “Stub” template by adding this anywhere in an article: {{Stub}}. Even though there are no parameters in this template, calling it produces the following text in an article when it is saved:

This article is a stub. You can help improve RichmondWiki.org by expanding it. Check our Help Content for more information about editing articles.

This template will categorize articles that include it into Category:Stubs.

We also use the “Closed” template to indicate if a business is closed. This template takes one parameter – the effective date of the closing. For example, on the Fat Larry’s page we added {{Closed|January 2009}} and this is what shows up on the page:

Fat Larry’s is no longer in business as of January 2009 and has been moved to the CLOSED category.

This is an easy way to alert visitors that this establishment is no longer open without having to add a lot of code to the page.

In Summary

Templates are a valuable and powerful way to make wiki editing and maintenance easier and more efficient. There’s much more that can be done with them, much of which is detailed in the Templates Help Page.

Now, go forth and show off what you’ve learned here. And as always, don’t be afraid to try out some editing tricks. YOU CAN’T BREAK A WIKI! That’s the best part! You can undo any changes you make if you don’t like them, and if you get REALLY lost another editor will most likely come by later and clean up any messes.

Leave a comment with any questions.

Possibly Related Posts:

  1. Simple Tip #4: Linking Between Articles
  2. Template:Stub
  3. Simple Tip #1: Add Categories

Leave a Comment

Previous post:

Next post: