Using Templates in Physiopedia

If you are creating a number of pages that have standard texts that you want to include, for example the same subheadings or a message at the top of the page, you may wish to create a template.

Templates are standard wiki pages whose content is designed to be transcluded (embedded) inside other pages. Templates follow a convention that the name is prefixed with “Template:” besides this, you can create them like any other wiki page.

The simplest use of templates is as follows. If you create a page called “Template:Welcome” with contents:

Hello! Welcome to the wiki.

you’ll have created your first template! If you then insert the code:

{{Welcome}}

in any other page, when that page is viewed the text “Hello! Welcome to the wiki.” will appear instead of {{Welcome}}. The template content is “transcluded” into the other page, i.e. it is integrated in the page.

You can then insert {{Welcome}} at any point of any page where you wish to welcome someone. Suppose it is used in 100 pages. If you then change the template contents to:

Hi there! Welcome to this wonderful wiki.

and revisit any of the 100 pages where the template was used, you’ll see the new text instead of the original one. In this way, you have changed the content of 100 pages without editing them, because the template is transcluded into these pages.

This is the basic mechanism. There are several additional features of transclusion that enrich this mechanism and make templates very useful.

Editing transcluded templates

If you wish to edit the template that has been transcluded on to each page individually, for instance if you are creating a set of subheadings on a page that will subsequently have different content added under each subheading, you will need to add the template to the page by inserting the code:

{{subst:Name}} i.e. {{subst:Welcome}}

this replaces the string  {{subst:Name}} with the contents of the template, in the source of the transcluding page, when you save that page; the copy of the template contents can then be edited normally (and separately from the original in the template page). Note: don’t use this if you are looking to continually propagate changes from the source template to the page(s) that references it.

Add your template to the ‘Templates’ page

Once you have created a template it is a good idea to record your new template on the ‘Templates’ page so that other people can use it or to remind yourself of the name that you gave it!

See the Creating Templates tutorial

Get more help with Templates here