From Meta, a Wikimedia project coordination wiki
This page is a translated version of the page Help:Template documentation and the translation is 41% complete.

Den här sidan handlar om att dokumentera mallar. Allmän mallhjälp återfinns på Help:Template.

Det finns flera sätt att dokumentera vad en mall ska göra:

  1. I vissa fall är det självklart på själva mallsidan utan vidare särskild förklaring.
  2. Det kan förklaras med <noinclude>...</noinclude>-taggar.
    Denna metod gör det möjligt att till exempel lägga till mallen i en mallkategori.
  3. Detaljerad dokumentation kan läggas på mallens diskussionssida.
    Denna metod blandas oftast med noinclude-strategin på mallsidan, med en hänvisning till diskussionssidan eller kanske en sammanfattning.

På mallsidan

Den delen av mallen som infogas definierar hur den fungerar när den infogas eller ersätts, medan den delen av sidan som inte infogas utgör själva sidan.

En typisk mallsida kan innehålla:

definitionsinnehåll, kanske en tagg för en kategori över sidor som innehåller mallen</includeonly><noinclude>
<nowiki><translate nowrap><!--T:14--> definition content, possibly formatted, annotated, summarized</translate></nowiki>

förklaring, exempel och taggar för mallkategorier (med sorteringsnyckeln {{PAGENAME}})

Mallnamnet utan kommentarstaggar kan vara användbara när mallen ersätts.

Till exempel för Template:T:

[[Category:Demo template]]

Detta visas som:


medan delen utan taggar som saknar information om innehållet kommer inte visas:


Alternatively the part of the definition content which is rendered without loss of information (in particular plain text) is not put in either type of tags, so that it does not have to be duplicated:

[[Category:Demo template]]

again rendered as:


Applying substitution without parameter produces this as wikitext. It can be displayed by subsequently putting nowiki tags around it.


If a template produces a table it is useful if the template page shows the table structure instead of the wikitext to make it. For that purpose the table syntax is not put in either type of tags, and the table elements, where needed, each have a noinclude and an includeonly part.


As shown above, in straightforward rendering of definition content, information is lost in the case of a parameter with a default value: only that value is rendered. Other cases where information is lost include:

  • #expr applied to an expression with a parameter gives "Expression error: unrecognised punctuation character "{"".
  • a variable is rendered as its value.

The parameter default mechanism can also be used to document what a parameter typically does:

  • An undefined {{{1}}} is rendered as {{{1}}}, clearly indicating that the template expects to get a first parameter.
  • An undefined {{{1|}}} displays nothing, that's probably the desired effect, but not helpful for a self-documenting template.
  • Maybe it's possible to indicate the function of an expected parameter, e.g. {{{1|image}}} for templates doing something with images.

Typically, examples in the noinclude-part include or substitute the template. Note that changes in the working of the template (i.e. changes outside the noinclude-part) are not yet effective in these examples in preview and, in the case of substitution, in "Show changes".


Some templates are designed to add pages to a given category. Sometimes it's good enough if the template page itself is also shown in that category. Generally that's not the case. Templates adding pages to a category then use:

...end of code<includeonly>[[Category:target]]
documentation and/or link to talk page
[[Category:template category|{{PAGENAME}}]]

Here target means a category for pages using the template, and template cat is a category for similar templates.

This method could be also used for interlanguage links in a template.

A small improvement seen on some templates replaces [[Category:target]] by [[Category:target]].

Normally the dummy parameter {{{category}}} is undefined (unused), and then the template adds pages to category target as before.

Setting category= (empty value) allows to disable this feature on lists of templates.

Otherwise template lists with examples would be added to the various target categories of templates explained by example.


Expansion demo templates can be used for live examples.

If a template contains a variable it can be useful if it has been written such that the value of the variable can be overridden by a parameter value, to demonstrate the effect of various values, using e.g.:

  • {{{namespace|{{NAMESPACE}}}}}
  • {{{pagename|{{PAGENAME}}}}}
  • {{{currentdow|{{CURRENTDOW}}}}}

This applies especially in the case of branching depending on the value of the variable.

Se även

Links to other help pages

Help contents
Meta · Wikinews · Wikipedia · Wikiquote · Wiktionary · Commons: · Wikidata · MediaWiki · Wikibooks · Wikisource · MediaWiki: Manual · Google
Versions of this help page (for other languages see further)
What links here on Meta or from Meta · Wikipedia · MediaWiki
Go · Search · Namespace · Page name · Section · Backlinks · Redirect · Category · Image page · Special pages · Printable version
Tracking changes
Recent changes (enhanced) | Related changes · Watching pages · Diff · Page history · Edit summary · User contributions · Minor edit · Patrolled edit
Logging in and preferences
Logging in · Preferences
Starting a new page · Advanced editing · Editing FAQ · Export · Import · Shortcuts · Edit conflict · Page size
Links · URL · Interwiki linking · Footnotes
Style and formatting
Wikitext examples · CSS · Reference card · HTML in wikitext · Formula · Lists · Table · Sorting · Colors · Images and file uploads
Fixing mistakes
Show preview · Reverting edits
Advanced functioning
Expansion · Template · Advanced templates · Parser function · Parameter default · Magic words · System message · Substitution · Array · Calculation · Transclusion
Special characters · Renaming (moving) a page · Preparing a page for translation · Talk page · Signatures · Sandbox · Legal issues for editors