Help:Templates: Difference between revisions

From SmashWiki, the Super Smash Bros. wiki
Jump to navigationJump to search
(→‎Template parameters: calling. might use examples)
Line 9: Line 9:
===Template parameters===
===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):
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.
# Supplying parameters in a unnamed list. This is typically done with templates with a low number of 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}}
#:'''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.
# 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}}
#:'''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>
#:<small>*Note that this example actually uses both parameter methods.</small>
Parameters can then be used inside the template itself with the syntax <code><nowiki>{{{parameter name/number|text to be inserted if the parameter is not supplied}}}</nowiki></code>.


===Substitution===
===Substitution===

Revision as of 09:08, February 18, 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 with a low number of 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.

Parameters can then be used inside the template itself with the syntax {{{parameter name/number|text to be inserted if the parameter is not supplied}}}.

Substitution

Building templates

Templates can be created by making a page in the template namespace. To do this, simply create Template:TemplateName.

Parameters

Conditionals and expressions

#if

#ifeq

#iferror

#ifexpr

#ifexist

#switch

#expr

Inclusion tags

includeonly

noinclude

onlyinclude