Help:Templates

From MiiWiki
Jump to navigationJump to search

Templates are special types of pages that can be put into other pages with extra parameters to modify them.

Types of templates

Basic templates

The most basic of templates are templates with no parameters, such as {{Welcome}}, which you can add to pages simply by putting the template name inside two curly brackets ({ and }) much like a link.

Templates with parameters

Templates with parameters are templates that can be modified to suit the page they are on. Parameters can be either numbers or words. On the template code, they are represented by putting the parameter name in three curly brackets. To use numbered parameters, simply put a pipe (|) after the template name within the brackets, and repeat for each number. To use word parameters, put parameter name= after the pipe and before the parameter content (it is also possible, but not required, to do this with numbers). Most templates have a section at the bottom explaining the purpose of each parameter.

Default parameter values

Parameters can be set to have default values by putting a pipe after the parameter name but before the three ending curly brackets and then the default value, similarly to calling a numbered parameter. You can also put nothing after the pipe to make the parameter not appear unless filled out (useful for if statements).

noinclude and includeonly

In order to avoid a mess of categorization and repeating template documentation every time they are called, noinclude and includeonly are used. <noinclude> should be put immediately after the part to be included in the page (transcluded) ends. Text that should not show up on the template itself, but should show up on the page it is included on (usually categories), wrap it in <includeonly> </includeonly>.

Adding content only if a parameter is filled

It is possible to only have content be filled out if a parameter is filled out. To do this, use {{#if:{{{parameter|}}}|What to display if the parameter is filled|What to put if the parameter is not filled}}. For more information on #if and similar functions (such as #ifeq), see the mediawiki extension page for it.

Using non-templates as templates

Pages besides templates can be used as templates by linking to them normally, except replacing the brackets with curly brackets. For mainspace pages, you will need to put a colon before the title. This is usually only used for testing templates in a sandbox.

Examples

Example of Template code Template display Template call code Called display
Basic template This is a template with no parameters This is a template with no parameters {{Template name}} This is a template with no parameters
Parameters This is a template with a numbered parameter with a default value ({{{1|default}}} and a named parameter ({{{param name}}} This is a template with a numbered parameter with a default value (default) and a named parameter ({{{param name}}}) {{{Template name|not default|param name=named parameter}} This is a template with a numbered parameter with a default value (not default) and a named parameter (named parameter)
includeonly and noinclude <noinclude>This appears on the template page but not the called instance of it</noinclude><includeonly>This appears on the called instance of the template but not the template page</includeonly> This appears on the template page but not the called instance of it {{Template name}} This appears on the called instance of the template but not the template page
if {{#if:{{{parameter name|}}}|This appears if "parameter name" is filled out |This appears if "parameter name" is not filled out}} This appears if "parameter name" is not filled out {{Template name|PARAMETER NAME=It doesn't matter what we put here if it does work, but it won't work here since parameter names are case-sensitive}} This appears if "parameter name" is not filled out