Help:Templates: Difference between revisions

From SmashWiki, the Super Smash Bros. wiki
Jump to navigationJump to search
(Will be a much more expanded version of Help:Templates, which I feel is severely lacking.)
Line 1: Line 1:
{{helppage}}
{{Draft}}
A '''template''' is a page, like its title says, a page which can be included into any other page, and sometimes be customized. This page gives tips on creating and using templates.
'''Templates''' are tools used in our articles that serve to both provide consistency and simplify the editing process. They may be used to quickly and easily build tables or infoboxes, or they could be used as link shortcuts. For a list of usable templates, see [[:Category:Templates]].
== Creating templates ==
 
Templates in most cases, are very easy to create. They should have the prefix '''Template:''' (see [[Help:Namespaces]]), but it doesn't need to be included to other pages.<br>
==Using templates==
This template below is an example. It can be included in the current page by typing {{tl|example}}.  "Example" is the name of the template, and the two curly braces are used to include it:
To use a template, the following syntax should be used: <code><nowiki>{{TemplateName}}</nowiki></code>. This is called "transclusion". For example, to use the template {{t|example}}, one would insert <nowiki>{{example}}</nowiki> in the place where the template should be included. The result will be the contents of [[Template:Example]]:
 
{{example}}
{{example}}


Sometimes, you may want to write about the template on its page (often to explain how and when to use it), but you don't want this text to appear on the template itself. To do this, you should enclose such text with <nowiki><noinclude> and </noinclude></nowiki> so that it does not appear on every page you use the template on. An example can be found in the {{tl|policy}} template. Below the box is a line of text that does not appear on policy pages. The opposite can also be made, by writing <nowiki><noinclude> and </noinclude></nowiki> tags around to only make text appear when included. This is very useful for categories.
===Template parameters===
Sometimes, a template will have required or optional parameters that need to be specified on the template's use. There are 2 methods of supplying parameters (which one should be used depends on the template in question):
# Supplying parameters in a unnamed list. This is typically done with templates that have only 1 or 2 parameters, such as {{t|SSB}}. To do this, simply add a bar ("|") after the template name, followed by the parameter's contents. This is to follow a <nowiki>{{TemplateName|Param1|Param2|Param3...}}</nowiki> format.
#:'''Example''': <nowiki>{{SSB|Mario}}</nowiki> returns {{SSB|Mario}}
# Supplying named parameters. This is usually used with templates the supply many parameters, such as {{t|Head}}. To do this, still add the bar, but instead of inserting the parameter's contents right away, add the parameter name (specified by the template) followed by an equals sign ("="), then the parameter's contents.
#:'''Example''': <nowiki>{{Head|Mario|g=SSB|s=16px}}</nowiki> returns {{Head|Mario|g=SSB|s=16px}}
#:<small>*Note that this example actually uses both parameter methods.</small>


==Modifiers==
===Non-template namespace===
By writing <nowiki>{{Namespace:Page name}}</nowiki>, pages from various namespaces can be included.
===Substitution===
===Substitution===
Templates can be substituted by writing <nowiki>{{SUBST:Template name}}, {{SUBST:Namespace:Page name}} or {{SUBST::Page name}}. By writing {{SUBST:Example}}</nowiki>, the content on {{tl|Example}} is placed on the page instead of just <nowiki>{{Example}}</nowiki> when someone edits.
 
===Linking===
==Building templates==
To link to a template without inserting it, use brackets instead of curly braces.
===Conditionals===
*<nowiki>[[Template:Policy]]</nowiki> will link to [[Template:Policy]]
===Expressions===
*<nowiki>{{policy}}</nowiki> will insert that template into an article.
===Inclusion tags===


{{helpnav}}
{{helpnav}}
[[category:help|Templates]]
[[category:Templates| ]]

Revision as of 18:35, January 22, 2016

Proposed.png
This page is a draft.
Feel free to contribute to this page as you would a mainspace page.

Templates are tools used in our articles that serve to both provide consistency and simplify the editing process. They may be used to quickly and easily build tables or infoboxes, or they could be used as link shortcuts. For a list of usable templates, see Category:Templates.

Using templates

To use a template, the following syntax should be used: {{TemplateName}}. This is called "transclusion". For example, to use the template {{example}}, one would insert {{example}} in the place where the template should be included. The result will be the contents of Template:Example:

Correct
The template was successfully included in this page.

Template parameters

Sometimes, a template will have required or optional parameters that need to be specified on the template's use. There are 2 methods of supplying parameters (which one should be used depends on the template in question):

  1. Supplying parameters in a unnamed list. This is typically done with templates that have only 1 or 2 parameters, such as {{SSB}}. To do this, simply add a bar ("|") after the template name, followed by the parameter's contents. This is to follow a {{TemplateName|Param1|Param2|Param3...}} format.
    Example: {{SSB|Mario}} returns Mario
  2. Supplying named parameters. This is usually used with templates the supply many parameters, such as {{Head}}. To do this, still add the bar, but instead of inserting the parameter's contents right away, add the parameter name (specified by the template) followed by an equals sign ("="), then the parameter's contents.
    Example: {{Head|Mario|g=SSB|s=16px}} returns Mario (SSB)
    *Note that this example actually uses both parameter methods.

Substitution

Building templates

Conditionals

Expressions

Inclusion tags