Help:Contributing/templates

From Wikibase
Jump to navigation Jump to search

Languages: English · français · Esperanto

A template is like any other page

A template is a regular static page living under the reserved namespace Template.

You create/edit a template exactly as you would do with any other classic MediaWiki pages.

Any page can embed one or more template(s)

The magic, is that MediaWiki automatically makes all templates embeddable, including in other templates. All you need to do is to call {{template name}}

For instance, if you have created a simple template named Template:Hello, which contains one simple phrase:

Hello! How is it going? It is good to see you!

And then in another page, say, User:DogFood, you write:

{{Hello}}

I am a dog lover! Hope you are as well!

You would get the rendered page:

Hello! How is it going? It is good to see you!

I am a dog lover! Hope you are as well!

Use templates whenever you want to repeat something often

If you are, say, creating a series of articles on your secret recipes, and you want to include a disclaimer at the top of each article, you will probably want to create a template called Template:EvaRecipeDisclaimer, then include the template by writing {{EvaRecipeDisclaimer}} at the top of each of your articles, rather than manually copying and pasting the same disclaimer onto all articles in the series one by one.

This way, if you later decide to change the disclaimer, you only need to update the template, not every article!

A template can also embed other templates

When you are building complex templates, you may find repeating patterns even in the templates themselves. Deduplicate even further by first building simple templates containing one or few basic elements, then build comprehensive full-page templates embedding multiple simple templates!

See Template:FOSS for a live example: it nests Template:FOSS/Infobox.

Although technically there is no limit on the layers of template nesting (a template can nest another template which nest another template which nest another...), it is seldom advisable to use more than 2 layers of nesting (simple template>full-page template>actual page). Multiple layer of nesting is inefficient and confusing.

Use <noinclude> for extra explanations

All content in a template, minus those wrapped between <noinclude></noinclude> is injected into pages that embed it.

For complex templates, you may want to include a usage instruction: that is where <noinclude> comes in handy.

Again, see Template:FOSS/Infobox for a live example.

See also

MediaWiki software doc on templates