Difference between revisions of "Help:Template"

m (Template moved to AoPSWiki:Template: in wrong namespace; to distinguish it from, for example, a C++ programming template)
(List: rmv category)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
A '''template''' is a page anyone can create.  An example template is [[Template:Stub]].  If someone creates an article that belongs in a certain category, they can add the template name for that category by adding the template name in double brackets at the bottom of the page, like so: {{category name}}.  For example, this page has the the template <nowiki>{{Tutorial}}</nowiki> at the bottom of the page.
+
{{shortcut|[[A:TM]]}}
  
== List of Templates ==
+
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 [[#Parameters|below]]), and similarly a change to a template will affect all articles that have the template. Any registered user can create a template page.
:''All templates can be found [http://www.artofproblemsolving.com/Wiki/index.php?title=Special%3APrefixindex&from=&namespace=10 here].''
 
  
== How to Create a Template ==
+
Template pages should generally be created in the Template (<tt>Template:xxxx</tt>) 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 <tt>Template:</tt> part, can be placed into double braces where the template is needed. Thus, to indicate that an article is a stub, add <tt><nowiki>{{stub}}</nowiki></tt> at the bottom of the article.
  
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 the following text (anything in bold can be changed):
+
There are many uses for templates. Some are used for categorization purposes, others can help with navigation, and some are applied as boilerplate messages.
  
<code>'''''This article is a sampleIt's purpose is to do this and that and this that.'''''
+
== Creation ==
 +
To create a template, which we will call "Sample" for the purposes of this tutorial, first navigate to the page <tt>Template:Sample</tt>.  Edit the page, then add:
  
<nowiki><noinclude>''This template will categorize articles that include it into [[:Category:</nowiki>'''Samples'''<nowiki>]].''</noinclude></nowiki>
+
<pre>
 +
'''''This article is a sample.
 +
It's purpose is to do this.'''''
  
<nowiki>[[Category:</nowiki>'''Samples'''<nowiki>]]</nowiki>
+
<noinclude>''This template will categorize articles
</code>
+
that include it into [[:Category:Samples]].''</noinclude>
 +
 
 +
<includeonly>[[Category:Samples]]</includeonly>
 +
</pre>
 +
 
 +
*The tags <tt><nowiki><includeonly></includeonly></nowiki></tt> 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 <tt><nowiki><noinclude></noinclude></nowiki></tt> 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 <nowiki>{{sample}}</nowiki> 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.''
 
Now, whenever you add the code <nowiki>{{sample}}</nowiki> 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 <nowiki>{{sample}}</nowiki> will automatically be added to Category:Samples.
 
Also, the page Category:Samples will be automatically created.  Any pages tagged with <nowiki>{{sample}}</nowiki> will automatically be added to Category:Samples.
  
==Parameters==
+
== Usage ==
A template can hold parameters. On the template page, add <code><nowiki>{{{1}}}</nowiki></code> to create a parameter. When transcluding the template, use the format:
+
As noted above, the general way to use templates is to add the name of the template in double braces. A keyword <code>'''subst:'''</code> will automatically transfer the contents of the template to the article. If you create an article which has <tt><nowiki>{{subst:Sample}}</nowiki></tt>, then when you view the page source again, that line will disappear and will be replaced by the actual coding of the template.
<pre>{{TemplateName| PARAMETER GOES HERE }}</pre>
+
 
 +
In general, it is preferable not to use this technique.
 +
:'''Pro'''s:
 +
*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.
 +
 
 +
:'''Con'''s
 +
*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.
 +
 
 +
 
  
Similarly, names can be used in the parameters. To create a parameter with a year, use <code><nowiki>{{{year}}}</nowiki></code>. For example, [[Template:Succession box]] uses:
+
== Cautions ==
<pre>{{Succesion box|before=1|title=The Number 2|after=3}}</pre>
+
*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 <tt>subst:</tt>-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]].
  
For more information about parameters, view the [http://en.wikipedia.org/wiki/Help:Template Wikipedia page on templates] (note that Parser Functions are disabled).
+
== List ==
 +
A list of templates can be found [http://www.artofproblemsolving.com/Wiki/index.php?title=Special%3APrefixindex&from=&namespace=10 here]. As the list of templates increases, a separate hierarchal system of template organization may be necessary.
  
[[Category:AoPSWiki]]
 
 
{{Tutorial}}
 
{{Tutorial}}

Latest revision as of 19:39, 11 December 2007

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.