8 min read

Page templates

Often times, we may have content that we need to include on several pages. For instance, we may want to include a legal disclaimer to certain pages. Or maybe we want to include a header or footer to all pages that fall into a specific category. Basically, if we have content that we want to include on more than one page, we can use a template. Creating a template means we don’t have to type the same disclaimer, or header, or footer every time we want to put it onto a page. Instead, we only have to create the template, and include the template tag wherever we want the content to be displayed. If this reason is not enough to make use of templates, consider this—if we want to change some of the content in let’s say, the disclaimer, we only need to change the template and all the pages will be updated. If we weren’t using a template, we would have to find each page where the disclaimer content was entered and make the necessary changes to keep it consistent. Using templates is just smart management.

Time for action – creating a template

We are going to use the URL method to create a new template. When we do this, we will create an empty page where we can create the template. Once it is saved, it can be added to any page we choose with the template tag {{templatename}}. Of course, the name we save our template as will be substituted for templatename.

For our sample wiki, we will create a template that adds a thank you to the user for supporting free and open source software. A link to both the Free Software Foundation and the Open Source Initiative will be included as well. This template can then be added to the bottom of each page that describes software.

  1. Open your web browser. In the address bar, type http://www.wikiname.com/index.php/Template:nameofyourtemplate . For the example wiki, we will enter http://www.flosspropopulo.com/index.php/Template:Thank you. Hit Enter
  2. .

  3. After you hit the Enter key, you will be taken to the new Template page. Click on edit this page to create and write the content for your template. For the sample wiki, we use:
    Thank you for supporting free and open source software.
    You can learn more about these projects
    from http://www.fsf.org and http://www.opensource.org.
  4. Click Show preview to see your new template. If you are satisfied, click Save page.
  5. Open an existing page in your wiki. At the bottom of the page, type {{templatename}} substituting your template for templatename. In the example, we will be opening the OpenOffice.org page and typing {{Thank you}} at the bottom.
  6. Click on Save page.
Organizing Your Wiki's Content in MediaWiki 1.1- An Extension

What just happened?

While creating a new template, we created a footer that can be added to any page simply by using the template tag in a page. This tag {{templatename}} is what placed the content below the horizontal rule in the previous screenshot. Anytime we include the tag for this template, {{Thank you}}, this piece of content will appear.

Templates with parameters

While the last use of the template tag can really benefit us when we are creating our pages, there is another manner in which we can use templates in our wiki. Do you remember when we created a new namespace called Tutorials? Let’s say that we want users to create tutorials for us on our site. Now, if we have 20 different users contributing tutorials, I will bet that there will be 20 different layouts for our tutorial pages. To help keep things more consistent, we can add parameters to our template so that it acts like a subroutine would in a program. Each page where we use this template would have the same parameters; however, the values for each would change. This keeps the pages in the tutorial namespace consistent.

A subroutine is a section of code in a program that executes a task that is one part of the larger program as a whole.

Time for action – using parameters in a template

While this may seem a bit difficult at first, after you complete the exercise you will see how simple it really is. If you have programming experience, the concepts of this should be second nature to you.

In our example, we will make the parameters boldface by enclosing them with ”’. However this is not necessary. What is necessary is for us to enclose the value of the parameter in triple brackets {{{ and }}}. For example:

”’parameter”’||{{{value}}}

Notice that the parameter is separated from the value by two pipes (||).

  1. Create a new template page using the URL method. For the example wiki, we will create a template called Tutorial by typing http://www.flosspropopulo.com/index.php/Template:Tutorial.
  2. Now, we need to create our template. We use the {| to open the syntax and |} to close it.
  3. Use some of the formatting techniques we have learned. For an example, we will use:
    {|style="width:80%; " border=0"
    |-
    |width=30%|
    |width=70%|
    |-
    | colspan="2" align="center"|'''{{{TutorialName}}}'''
    |-
    |'''Introduction'''||{{{intro}}}
    |-
    |'''Prerequisites'''||{{{prereq}}}
    |-
    |'''Steps'''||{{{steps}}}
    |-
    |'''Summary'''||{{{summary}}}
    |}

  4. This can serve as a guide for you as well. Simply change the parameters and the values to something that better reflects your wiki.
  5. Make sure the syntax is correct by clicking on Show preview. If everything looks like the following screenshot, you can click Save page. If anything is off, double check your syntax and make the necessary corrections.
    Organizing Your Wiki's Content in MediaWiki 1.1- An Extension

    Now that we have created the template let’s put it to use. We will need to pass on values on to our parameters on this page.

  6. Open a new page for editing.
  7. Open the template with double brackets {{. Using the example, we would type {{Tutorial |. Make sure to end this line with a pipe. Hit Enter to drop to the next line.
  8. Now we will pass values on to the parameters. Type your first parameter followed by an equal sign (=) and the value. For example, TutorialName = Installing MediaWiki|. Hit Enter and give your next parameter a value. Continue with this until all parameters have a value.
  9. Close the page with double brackets, }}.
  10. Click Show preview to see if everything is good. If you like what you see, click Save page.
  11. Organizing Your Wiki's Content in MediaWiki 1.1- An Extension

What just happened?

Using the template namespace, we were able to assign parameters to our template. Now, we can apply this template to any page that we want to have a consistent look. Once we declare this template on a new page, we need to pass values on to the parameters. If you don’t pass a value to a parameter, it will display the wikitext for the missing parameter. For example, if we fail to include an Introduction using the sample tutorial, the page will display {{{intro}}} where the introduction would be. The pages will now have the same layout, however the content will change. Using this technique, we created a template called Tutorial for the sample wiki and applied it to a new page. We also saw that we can apply many of the formatting techniques we have learned so far to our template to give it a more unique look and to separate items on the page.

Have a go hero

Templates are a great way to give your wiki a consistent look. Go ahead and create some templates that you can apply to pages in your wiki. For starters, create a disclaimer or some other type of footer that you will use on certain pages and apply this template to your wiki. Once you have been able to master this, go ahead and create a template that makes use of parameters unique to your wiki.

If you are interested in learning more about parameters used with templates, search the Internet for Named and Numbered parameters. You can visit the MediaWiki page: http://meta.wikimedia.org/wiki/Help:Template#Parameters that specifically addresses parameter use in a template.

Page redirection

If you have spent any significant time surfing the web, you must have surely come across an instance when you follow a link but are redirected to another page. Generally, this happens for one of the two reasons, either because the content you are looking for has been moved to a different page, or because the page you are on has a similar URL to the page where the content is housed. The latter happens frequently when someone has multiple domains all pointing to one website. For instance, www.mysite.com hosts the website but www.mysite.org and www.mysite.net redirect to www.mysite.com so that visitors can view the content.

Both instances would be ideal scenarios where we would redirect a page in our wiki as well. Take for instance our page OpenOffice.org from the example. Perhaps someone wrote an article on Star Office years ago. When the name was changed to OpenOffice.org, we could redirect the Star Office page to the newly created OpenOffice.org page. The second instance from above could be used because generally, people refer to OpenOffice.org as simply Open Office. We could then create a page called Open Office and redirect it to the OpenOffice.org page. Both are accomplished by adding the wikitext: #REDIRECT [[Article name]] to the beginning of the edit box. It is important to note that when redirecting an article that contains content, the content does not move to the new page.

You can create a new page with the redirect tag as well.

LEAVE A REPLY

Please enter your comment!
Please enter your name here