Help:Templates
What is 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:
", assigning it to that namespace. Therefore you can create them like any other wiki page.
Example of templates
Templates are commonly used in wiki pages, For example,
- The Start template tab used in the FRST 522 course. It is a good template to organize course contetn
- The mbox template used in help documentation on how to create a table. It is a useful template when you want the reader to pay attention on certain part of the information.
- The infobox template, which are often customized and used typically in course pages or resources page.
Why use templates?
Using templates are convenient especially when you want to add dynamic elements to the page. Instead of copy and pasting a complicated wiki text, you can just add a template by clicking on inserting button.
How to add a template
On Visual Editor
- From the editor screen, go to Insert>Template.
- Type the name of the template and then press Add templates.
- Some template requires you to add parameters. (Such as mbox template) , and for some it does not require to (Such as draft template) . For more details, usually you can click on the its page link after the paragraph "There might be some additional information about the ___template on its page. Then, press Apply changes to add the template to the page.
- You're done! You have now inserted a template! Below is the result of the mbox template.
On Wikitext
Templates are wiki pages which can be used in other pages in three ways:
{{Name}}
'transcludes' (i.e. includes a copy of) the content of the template (stored in the page [[Template:Name]]) whenever the page containing the template transclusion is fetched and displayed; i.e. if the template is later changed, the displayed transcluding page will automatically change too{{subst:Name}}
replaces that string 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). To Note: don't use this if you are looking to continually propagate changes from the source template to the page(s) that reference{{msgnw:Name}}
includes the template in a form that displays it as raw wiki syntax (the way<nowiki>
does) when the page containing it is fetched.
In fact, an ordinary wiki page can also be used as a template, simply by specifying the namespace it resides in, so:
{{Template:Pagename}}
includes[[Template:Pagename]]
{{Foo:Pagename}}
includes[[Foo:Pagename]]
{{:Pagename}}
includes[[Pagename]]
{{subst::Pagename}}
replaces itself with the contents of[[Pagename]]
If no such namespace exists, the full title is assumed to be a template:
{{Foo:Bar}}
includes[[Template:Foo:Bar]]
Parameters
You can define parameters in templates either numbered as {{{1}}}
or named {{{param}}}
. Please note that there are a set of three curly braces ({{{
and }}}
) around each parameter. This is different from normal template name usage.
When using the template on a page, you fill in the parameter values, separated by a pipe char (|): {{Thankyou|all your hard work|Joe}}
. For named parameters use "name=value" pairs separated by a pipe char: {{Thankyou|reason=all your hard work|signature=Joe}}
. The advantage of using named parameters in your template is that they are flexible in order. It also makes the template easier to understand if you have many parameters. If you want to change the order of numbered parameters, you have to mention them explicitly: {{Thankyou|2=Joe|1=all your hard work}}
.
You can also provide default values for parameters, i.e. values that are going to be used if no value is provided for a parameter. For example, {{{reason|all your hard work}}}
would result in "all your hard work" if no value was provided for the parameter reason.
Where to find template?
Organization
Layout
Design
Course
There are also many other templates available at UBC_Wiki:Templates
Make your own template
Please feel free to add templates to contribute to the UBC Wiki community!! To learn how to make templates, see Help:Create_Templates