Microtonal Encyclopedia:Template documentation

Templates are a very powerful feature of MediaWiki, but can be confusing to new users and even experienced users can have difficulty making sense of the more complex ones. Templates should therefore be accompanied by documentation to improve usability.

Template documentation should explain what a template does and how to use it. It should be simple enough that a user without complete knowledge of the intricacies of template syntax—which includes many experienced contributors who focus their attention elsewhere—can use it correctly. This is especially true in the case of very widely used templates.

Editors should defer to official policies or guidelines when template documentation pages are inconsistent with established community standards and principles. Editors should also avoid "quoting" template documentation pages as though they are policy—including this how-to guide. Template documentation pages can be written without much—if any—debate, as opposed to Wikipedia policies that have been thoroughly vetted by the community (see WP:Local consensus for details).

What to include
Template documentation should cover:
 * The basic purpose of the template: what it does and if it is not immediately obvious, why it needs to be done. If there are other templates with similar names or purposes, it's a good idea to mention those, in order to reduce the chance of the wrong one being used. Include important limitations, such as the lack of Navbox visibility on the Mobile web site, if a template should only be used for certain countries or time periods, or other things that editors need to know before choosing to use the template.
 * The parameters of the template: whether they are numbered, named or optional, and if so, what the default values are and what effect they have. If a parameter can take only a limited set of values or is constrained in any way, for example, if it can only use "yes", "no", or a number, this should be clearly explained.
 * Usage examples: specify the exact wikitext that should be used and the result that it produces. The wikitext can be enclosed in a  container, to make it clear and . If the template can be used in several different ways, with or without optional parameters, for example, provide a range of examples. A good way to do so is to transclude the template itself into the documentation a few times (i.e., use live examples), with different parameters each time and list the parameters used in each case. With Template:Xpd this can be done without putting the template call twice in the wikitext.
 * TemplateData: See TemplateData/Tutorial.
 * Related templates: if the template is one of a series of templates, include links to these – in particular, ensure that every template in the series is linked from each of the others, as this makes navigation easier. (A separate navigation template may be useful for this purpose, see: Template:Protection templates).
 * Categories where applicable (InterWikimedia links should be listed at Wikidata – more information at Wikidata). Like the documentation, categories must be listed within a  container on a template, or within  tags if placed on a documentation page. Many template categories are available, see: Category:Wikipedia templates to browse through them.

The English Wikipedia is a source of templates for hundreds of other Wikipedias and sister projects. Often, templates are fully self-contained, so the process easy: the contents are simply copied to a new template page at the other wiki, and everything works. However, on more complex templates, the template may invoke a module, transclude other templates, only work if paired with a separate template, or need particular CSS or Javascript code to work. In these cases, it is helpful to include a brief list of templates or other code that this one requires, at the end of the documentation.

Where to place it
A template's page in the Template: namespace is the location for the template code that controls the look and behavior of that template. What usually appears underneath the title on the rendered Template: page (as opposed to the edit window on the Edit tab or, in the case of templates whose code is protected, the View source tab, is the rendered template itself, followed by a separate section to display the template's rendered documentation, followed by the categories to which the template belongs.

However, the editable wikicode for the template's documentation is often placed on a separate subpage of the template itself, which is then transcluded at the end of the template page. This separates the often complex template code from the documentation, making the documentation easier to edit and reducing the number of accidental editing errors in the template code. It also allows templates to be protected where necessary, limiting editing access to important templates' code while allowing anyone to edit those templates' documentation. This method is sometimes referred to as the "template-doc page pattern".

Documentation of any sort on a template page (including TemplateData) should always be enclosed by a  container, so that it does not show up when the template is used on another page. Text that is on a template page itself adds to the amount of text that must be processed when displaying the template, which is limited for performance reasons. Placing the documentation in a transcludable subpage avoids this. MediaWiki developers, who create the program that the Wikimedia Foundation's wikis run on, have recommended this placement for this very reason.

How to create a documentation subpage
Template documentation subpages should be named and formatted using the following general pattern, for consistency.

Suppose your template is named. Create a subpage with the name. See the details at Documentation subpage or start the page by copy-pasting the following standard wikitext:

The top line will display a message explaining the current page and a link to the template page.

Insert the documentation after the top line and categories under the appropriate comment line – leaving the comment in place, so that the layout is preserved when the page is edited in future. Related templates, policy page, projects, etc. can be linked to by adding a "See also" section.

Save the subpage and return to the template itself,, in this example. Edit the template and append the following at the end of the template code:

&lt;noinclude>

&lt;/noinclude>

This will transclude documentation at the bottom of the template page.

Important: Make sure the opening begins immediately after the last character of the template code or text and not on a new line, nor with any intervening spaces. Otherwise, extra space will be inserted below the template when it is used, which is usually not wanted.

If the template is already protected, ask an administrator to do this or request an edit by using an edit protected on the template's talk page. If documentation and categories already exist in a section, enclosed within a  container, move them into the documentation subpage (where they should be enclosed in ), as it is best not to have documentation split across two separate pages.

If the code is put on the template page first, one can benefit from the preload feature to get a pre-filled doc page skeleton; if the documentation page does not exist yet, clicking the edit link on the template page will preload the contents of Template:Documentation/preload into the editbox of the /doc subpage creation.

You may wish to redirect the talk page of the /doc subpage to the talk page of the template itself. Then all talk relating to the template and its documentation will end up on the same talkpage. For example, redirect  to.

Blank
To generate a blank template, which may then be copied from the documentation and pasted into another page, use:



Examples
To generate an instance of the template, populated with its own property names, use:



Categories and interwiki links

 * To place the template itself into a category, add the  code inside an  section on the doc subpage.
 * To create an interwiki link for the template itself, go to Wikidata and follow the instructions for adding links to pages.
 * To place the doc subpage into a category, add the  code inside a  section on the doc subpage.
 * To make the template place an article into a category (when the article includes the template), add the  code inside an <includeonly ></includeonly> section on the template page. Exact placement within the template code may affect how the category code is executed.

/sandbox and /testcases
Before doing changes to a template it can be good to first copy the template code to a sandbox and run some testcases, since the template might be visible on thousands or even millions of pages. If you create subpages named exactly "/sandbox" and "/testcases" to a template then the green box on the template auto-detects this and will show links to those pages in its header. See Template sandbox and test cases for more information.

Several templates, one documentation page
When several templates work together or are very similar then it is often clearer and easier to maintain one single documentation page that documents them together. The simplest way to do this is to make a full documentation page at one of the templates, and then make "soft redirects" from the other templates. See, for instance, wrap.

When no documentation is needed
When a template as displayed will link to a page that can serve as the documentation, then separate documentation is superfluous and does not need to be created. See, for instance, a stub template, which, when displayed, will link to Stub. However, this is very rare.

Tips and tricks
Here are some tips to facilitate writing documentations:
 * Links to templates like can be inserted by writing . See tlp for similar templates.
 * HTML tags like <ref ></ref> can be easily inserted with tag. This example is written as
 * Equals sign = can be inserted with . For example, is made by . Avoid the equivalent notation &amp;#61; which is not easy to read for other editors.
 * Don't forget the single tag.  example becomes  example, and [ http://en.wikipedia.org no link] is [ http://en.wikipedia.org no link]. See WP:NOWIKI for the details.
 * For a link to a category, use cat. For example, becomes.
 * To suppress categorization of the /sandbox and /testcases pages of the template (if they exist), use this code at the bottom of the documentation subpage:

&lt;noinclude>&lt;/noinclude>
 * When the template is a child infobox, documentation appears broken. Prevent this by adding the &lt;includeonly> tag: