Help:Template

(Redirected from AoPS Wiki:Template)
Shortcut:

A template is a page that is transcluded onto other pages for the sake of organization and efficiency. All pages with a template will show the same thing (with the exception of parameters, see below), and similarly a change to a template will affect all articles that have the template. Any registered user can create a template page.

Template pages should generally be created in the Template (Template:xxxx) namespace, though all articles can be transcluded. An example template is Template:Stub. To utilize the template, in the article the name of the template, minus the Template: part, can be placed into double braces where the template is needed. Thus, to indicate that an article is a stub, add {{stub}} at the bottom of the article.

There are many uses for templates. Some are used for categorization purposes, others can help with navigation, and some are applied as boilerplate messages.

Creation

To create a template, which we will call "Sample" for the purposes of this tutorial, first navigate to the page Template:Sample. Edit the page, then add:

'''''This article is a sample.
It's purpose is to do this.'''''

<noinclude>''This template will categorize articles
that include it into [[:Category:Samples]].''</noinclude>

<includeonly>[[Category:Samples]]</includeonly>
  • The tags <includeonly></includeonly> denote items that only appear on the template page and not on the articles that they are transcluded in. Often, documentation will belong here to help other users understand how to use the template.
  • The tags <noinclude></noinclude> denote items that only appear on the articles they are transcluded in and not on the actual template page. This is often used to prevent the template from being listed on the category page.

Now, whenever you add the code {{sample}} at the end of an article, it will display the text "This article is a sample. It's purpose is to do this and that and this that. Also, the page Category:Samples will be automatically created. Any pages tagged with {{sample}} will automatically be added to Category:Samples.

Usage

As noted above, the general way to use templates is to add the name of the template in double braces. A keyword subst: will automatically transfer the contents of the template to the article. If you create an article which has {{subst:Sample}}, then when you view the page source again, that line will disappear and will be replaced by the actual coding of the template.

In general, it is preferable not to use this technique.

Pros:
  • If the template is vandalized in the future, then the vandalism will not show up in the article.
  • On templates for talk/user talk pages, it is better to show the direct source code then to just show the name of the template in the source as better netiquette.
  • You do not have to navigate to a different page to see the source code of the template.
Cons
  • A good change to the template will not be updated on the articles the template is transcluded (it's dynamic).
  • For templates with complex coding, seeing the code is unpreferable and potentially overwhelming.
  • It is hard to trace the source code back to the template that was used.


Cautions

  • When using templates that should go inline, be careful that there is no extra line. If there is, then a line break will appear on the article it is to go in. To avoid this, squeeze the includeonly and noinclude tags in one line.
  • Remember than an edit to a template that is not subst:-ed well show up on every page the template is used in. Before making an edit to a template, be sure to use the “Show Preview” button, and for more complex edits/templates try experimenting in the AoPSWiki:Sandbox.

List

A list of templates can be found here. As the list of templates increases, a separate hierarchal system of template organization may be necessary.

This article is a tutorial about the AoPSWiki or AoPS Forum.