Difference between revisions of "Help:Template"

(List: rmv category)
 
(18 intermediate revisions by 6 users not shown)
Line 1: Line 1:
== Categories ==
+
{{shortcut|[[A:TM]]}}
  
A category is a page where all articles with a similar theme are listed.  An example is Category:Stubs. All articles that were categorized with the <nowiki>{{stub}}</nowiki> formatting will be in this category.  To directly add a page to a category, use the <nowiki>[[Category:Insert Category]]</nowiki> code. This page, for example, displays the <nowiki>[[Category:AoPSWiki]]</nowiki> code at the bottom.
+
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.
  
=== List of Categories ===
+
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.
Category:Academic Resources
 
Category:AoPSWiki
 
Category:Stubs
 
Category:Tutorials
 
  
== Templates ==
+
There are many uses for templates. Some are used for categorization purposes, others can help with navigation, and some are applied as boilerplate messages.
  
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.
+
== 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:
  
=== List Templates ===
+
<pre>
[[Template:Stub]]
+
'''''This article is a sample.
[[Template:Tutorial]]
+
It's purpose is to do this.'''''
  
 +
<noinclude>''This template will categorize articles
 +
that include it into [[:Category:Samples]].''</noinclude>
  
=== How to Create a Template ===
+
<includeonly>[[Category:Samples]]</includeonly>
 +
</pre>
  
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):
+
*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.''
 +
Also, the page Category:Samples will be automatically created.  Any pages tagged with <nowiki>{{sample}}</nowiki> will automatically be added to Category:Samples.
  
'''''This article is a sample. It's purpose is to do this and that and this that.'''''
+
== Usage ==
 +
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.
  
<nowiki><noinclude>''This template will categorize articles that include it into [[:Category:</nowiki>'''Samples'''<nowiki>]].''</noinclude></nowiki>
+
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.
  
<nowiki>[[Category:</nowiki>'''Samples'''<nowiki>]]</nowiki>
+
:'''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.
  
----
 
 
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.
 
  
  
 +
== 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 <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]].
  
----
+
== 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.