Creating a template

From WikiEducator
Jump to: navigation, search




Icon preknowledge.gif

Preknowledge

Before proceeding with the tutorial you need to:
  • Decide what kind of template you want to create:
  • Decide on a suitable name for your template. It is usual practice to use a descriptive abbreviation of the corresponding content page where you want to use the template, for instance "Gardening_Nav" for a template for the Gardening page or "WET15_Nav" for a template that will be used on Tutorial 15 of the WikiEducator Tutorials.
  • Know what sections and subsections are needed for your navigation template.


Only three steps to go!
Flickr-logo.png
CC-BY.png

Image courtesy of Jan Tik
If you're not sure of the answers to these questions yet, then you are probably not ready to proceed with this tutorial. Many content developers find it easier to create and insert their navigation templates after the basic structure becomes apparent once a few content pages have been created. The Tutorial on developing a teaching resource in WikiEducator is a good starting point for planning a content project.

A three-step process

Creating and using templates is a three step process:

  1. First you need to create a new template page;
  2. Then you need to generate the content for your template and save the template page;
  3. Finally, you need to insert a reference on your content pages in the main wiki namespace to call the content from your template.

Creating a template page

To create a template you need to create a page with Template: as the first part of the name. Up to now, we have created new pages in the wiki by making a link in some content to a page that doesn’t exist yet, then following the resultant red link to edit the new page (see for example: Creating new pages).

Templates are a little different because we are not really creating a link to the template itself, but will reference it on an existing content page. So we first need to create the template page before we can use it on a content page.

The easiest way to create a new template is to manually enter the name of the template into the URL bar of our browser after the http://www.wikieducator.org/ part, then either hit enter or the Go button. Like this:

Enter the name of the new template you wish to create in your browser like this: http://www.wikieducator.org/Template:New template then click on the edit this page link to create your template.



Icon activity.jpg
Activity
The purpose of this activity is to create your first template page in the wiki.
  1. After the URL "http://www.wikieducator.org/" enter the name of your template in the following format:
    • Template:Name_of_template_goes_here, so for example, if you are creating a navigation template for a page on Gardening, you would enter the following in your URL bar of your browser: http://www.wikieducator.org/Template:Gardening_nav
  2. After pressing the <enter> key, you should see the following message:
    • "There is currently no text in this page, you can search for this page title in other pages or edit this page." Click on the "edit this page link or click on the red "Template" tab - see screenshot below.
  3. Enter the following temporary text: "This my draft template text ..." and save the template
  4. Write down the name of your template page as you will need this later in the tutorial.



Click on the "Template" tab or "edit this page" link to create the template.

Inserting a reference to call your template on a content page

Your template is just like any other wiki page and can contain any wiki markup or HTML code. In the previous activity you saved a temporary text which you can use to test whether your template is working. On the wiki page where you want to call the content saved in your template, you enter the name of your template between two curly braces. So for example, if the name of your template was Gardening_Nav, you would enter the following syntax on the relevant content page:

{{Gardening_Nav}}



Icon activity.jpg
Activity
The purpose of this activity is to test whether your template is functioning properly.
  1. Go to your sandbox on your user page
  2. In the edit mode, enter the following syntax {{Name_of_your_template_goes_here}}
  3. Click on the save button and see whether the text you saved in the previous activity is displayed in your sandbox.



Icon present.gif
Tip: Remember that:
  • It is standard practice to include the navigation template at the top of your content page.
  • The name of your template is case sensitive so you must use the exact capitalisation and lowercase letters used when you saved your template;
  • If you can't find or remember the name of your template, click on the "my contributions" link at the top of your browser. Look for the most recent page you edited in the Template namespace;
  • You can insert the call for a template on any content page by inserting the same syntax, i.e.: {{Name_of_your_template_goes_here}}
  • In the next section of the tutorial we will replace the temporary text with the syntax required to set up a navigation template.


Choosing the right type of navigation template

WikiEducator has prepared special navigation templates to simplify implementation and to encourage a consistent look and feel of our content pages. These special templates are easier to use because you can cut and paste the syntax without needing to worry about more complex html formatting. We have two generic template formats, so before you proceed you should decide on the type of navigation template you want to use:

  1. Navigation for project nodes or community hubs in WikiEducator (like the Learning4Content initiative) -- In this case you should proceed with section on templates for project and community nodes;
  2. Navigation for structured content with sections and subsections (like the navigation used for Developing a teaching resource -- In this case you should continue with the section on templates for structured content.