User:DavidJCobb/Editor's Guide/Templates

From ZeldaChaos
Jump to: navigation, search

This page is a guide to creating templates.

Contents

Creating a test template

It's generally a good idea to first create your templates as a subpage of your userpage; this is to prevent cluttering the Template namespace with templates that are incomplete or don't work. It is possible to use pages that aren't in the template namespace as templates; simply specify the namespace with the template name, e.x.

{{User:TemplateMaker/A Template Im Working On}}

Specifying Parameters

When including a template, it is possible to specify values that the template should "receive". While the template is operating, these values are stored in special variables called parameters. There are two types of parameters: named parameters and unnamed parameters.

Named Parameters

Named parameters are simply parameters that have a name in them. To pass named parameters to a template, include it like this:

{{Template|name=value|name2=value2}}

Where Template is the template's name, name is the name of the parameter, and value is the name of another parameter. You can specify as many parameters as you want; separate them with the vertical pipe symbol (|).

Unnamed Parameters

Unnamed parameters are specified identically to named parameters, except that the name portion is left out.

{{Template|value|value2}}

Unnamed parameters are actually just shorthand for parameters that have numbers as names. The first unnamed parameter is really a parameter named '1'. This means that the following three codes do the same thing:

{{Template|ABC|DEF}}
{{Template|1=ABC|2=DEF}}
{{Template|2=DEF|1=ABC}}

Using Parameters

To use a parameter, simply type the parameter's name, enclosed in three sets of curly braces (like this: {{{parameter}}}. Of course, this can cause a problem -- if the parameter isn't specified, then {{{parameter}}} will actually show up as part of the output. This can be fixed, though, by specifying a default value for the parameter.

Specifying a Default Value For a Parameter

To specify a default value for a parameter, use the vertical pipe symbol inside the parameter code:

{{{parameterName|defaultValue}}}

That code would include the parameterName parameter, unless parameterName is undefined, in which case "defaultValue" is written to the page. This parameter substitution allows for the creation of simple logical structures such as the switch-case template.

Personal tools
Namespaces

Variants
Actions
Glitches
Navigation
Affiliates
Toolbox
Google AdSense