How to create templates in wiki

From NEOSYS Technical Support Wiki
Jump to navigationJump to search

1 Creation

Templates are standard wiki pages whose content is designed to be embedded inside other pages. Templates follow a convention that the name is prefixed with "Template:", assigning it to that namespace; 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}}.

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

Now, 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 all.

This is the basic mechanism of templates.

2 Parameters

Parameters allow the template to produce different contents or exhibit different behaviour.

When using the template on a page, you fill in the parameter values, separated by a "pipe" character (|).

Suppose you wish to modify the Welcome template mentioned above so that it greets different users by their names, for example:

Hello Ashwin! Welcome to the wiki. 
OR 
Hello Steve! Welcome to the wiki.

Then, in such cases, the "Template:Welcome" must contain the following text:

Hello {{{1}}}! Welcome to the wiki.

Note - Notice the use of {{{1}}}. This is the way to identify, within templates, the parameters that will be passed in when the template is used. Each parameter is surrounded by three braces: {{{ }}}. This is different from normal template name usage.

Now, If you insert the code:

{{Welcome|Ashwin}}

in any page then, when that page is viewed, the text "Hello Ashwin! Welcome to the wiki." will appear instead of {{Welcome|Ashwin}}.

Similarly, If you insert the code:

{{Welcome|Steve}}

in any page then, when that page is viewed, the text "Hello Steve! Welcome to the wiki." will appear.

3 Finding Templates

To find Templates, users can:

  1. Click Special Pages > All Pages
  2. In the Namespace list, choose Template and click Go.