Help:Template

From SmartEnoughWiki

Jump to: navigation, search

Using Mediawiki, the function of templates is to transmit the (whole) contents of one onto another page via a process called transclusion. If a page is specially intended for this purpose it is called a template.

Contents

[edit] Template namespace

The template namespace is the namespace with prefix "Template:" For example:

[[Template:Be Bold]]

A page in this namespace is designed to be useful for insertion in other pages.

[edit] Creating a Template

You create templates like you would any other page - by linking to them. You can create templates on the fly - if the page to be transcluded does not exist, then a link to the edit page is produced when you save the edit. Thus, you make a template by putting the tag first, and then following the link.


[edit] Inserting a Template

The syntax for inserting a template is just a link using curly brackets instead of square ones.

{{Name of Template}} note that you don't have to put in the "Template:" prefix - it is assumed.


To create a hyperlink to a template page, use the usual wikilink syntax [[Template:name]].

[edit] Using other pages as templates

The pages in the namespaces other from "Template" namespace can also be used as templates. To use a page in the main namespace as a template, add a colon before the page name. Eg:

{{:Books}}


An exception is that transclusion of a "non-existing" page in the MediaWiki namespace trancludes the default content of that page. In other words, apart from transcluding a page one can also transclude a [[Help:System messages|system message]] in a specified language (by default the site language); the result is independent of the user-specified interface language.<br>

One can call a template that calls another template.

[edit] Templates with parameters

You can call a template while specifying variables or parameters to be used in that template.

For example, you can add a template to a page that says

Protected page: This page was protected by Username for the reason: It is awesome right now!

Where 'username' and 'reason' are defined in the template call.

To enable this you have to create numbered placeholders for the parameters in the template. This Template:Protected will contain the following:

:'''Protected page:''' This page was protected by '''{{{1}}}''' for the reason: ''{{{2}}}''

Note that the leading colon here indents the output of the template, which would otherwise appear inline whereever it was called.


To call it, use this syntax:

{{Protected|Michael|It is awesome!}}

example: the protected template in action:

Protected page: This page was protected by Michael for the reason: It is awesome!