Community Central
Community Central

Templates allow you to pass parameters that can be used to affect the content or design of the template.

Simple replacement

Using the example of a simple box, the following when placed on a template page called Template:Box:

Template code

<div style="width:10em; height:5em; border:1px solid #333; background-color:#666; color:#fff; text-align:center; padding-top:2em;">{{{1}}}</div>

Produces the following box on the template page:

{{{1}}}

Article code

Next, on an article, you could type:

{{box|something}}

This would produce:

something

This is because {{{1}}} tells the wiki to pass the first parameter of the template here. This can be extended with {{{2}}}, {{{3}}}, ad infinitum. The number represents the number of the parameter:

{{box|first parameter|second parameter|third parameter}}

If you wish not to use a certain parameter, you can leave it blank, but the | must still be included. For example:

{{box|first parameter||third parameter}}

Named and default parameters

As an alternative to the above, you can use named parameters. Though this makes the code slightly more complex, it allows more freedom in how templates are created.

Template code

Again, using the example of Template:Box:

<div style="width:10em; height:5em; border:1px solid #333; background-color:{{{bgcolor|#666}}}; color:{{{textcolor|#fff}}}; text-align:center; padding-top:2em;">{{{text}}}</div>

{{{text}}} introduces the concept of a named parameter. {{{bgcolor|#666}}} also introduces the concept of a default parameter - if bgcolor is not defined, #666 will be passed.

Article code

{{box|bgcolor=yellow|textcolor=red|text=A yellow box}}

Produces:

A yellow box

As the parameters have names, you can pass them in any order, so {{box|textcolor=black|text=A blue box|bgcolor=blue}} would produce an identical box.

Due to default parameters, if, say, the background color was not defined - as in {{box|textcolor=red|text=A yellow box}} - you would get:

A yellow box

See also