MeritBadgeDotOrg:Template documentation

From MeritBadgeDotOrg

Revision as of 20:52, May 17, 2012 by Miksmi (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Template:How-to

Please discuss any major changes you want to do to this page or the templates and pages related to this page on the talk page first.

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 one. 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.

Contents

What to include

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, to reduce the chance of the wrong one being used.
  • Any parameters that the template takes. Explain whether they are numbered or named, whether they are optional (and if so, what the default value is), and what effect they have. If a parameter can take only a limited set of values (“yes” or “no”, for example), must be a number, or is constrained in some other way, this should be made clear.
  • Usage examples. Specify the exact wikitext that should be used, and the result it produces. The wikitext can be enclosed in a <code>…</code> container to make it clear and easy to copy, like this. 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.
  • 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 for example Template:Protection templates).
  • Appropriate categories and interwiki links, where applicable. Like the documentation, these must be within a <noinclude>…</noinclude> container. Many template categories are available, go to Category:Wikipedia templates to browse through them.

Template documentation is often placed in a 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. It also allows templates to be protected where necessary, while allowing anyone to edit the documentation. This method is sometimes referred to as the “template doc page pattern”.

Documentation of any sort on a template page should always be enclosed by a <noinclude>…</noinclude> container, so that it does not show up when the template is used on another page. Text on the template page itself adds to the amount of text which must be processed when displaying the template, which is limited for performance reasons. Placing the documentation in a subpage avoids this (MediaWiki developers have recommended it for this reason).

How to create a documentation subpage

Documentation subpages should be named and formatted using the following general pattern, for consistency.

Suppose your template is named Template:X. Create a subpage with the name Template:X/doc. See the details at {{Template doc page}} or copy-paste the following wikitext as a start for your documentation:

{{Template doc page}}   
<!-- 
    PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE
    YOU CAN EDIT THE TEMPLATE DOCUMENTATION BELOW THIS COMMENT
-->
==Usage==


==See also==


<includeonly>

<!-- PLEASE ADD CATEGORIES BELOW THIS LINE, THANKS. -->


<!-- PLEASE ADD INTERWIKIS BELOW THIS LINE, THANKS. -->


</includeonly>

The top line will display one of two templates – {{Template doc page transcluded}} or {{Template doc page viewed directly}} – at the top of the documentation; this makes it clear to the reader that what follows is documentation, and provides a link to edit the /doc subpage.

Insert the documentation, categories and interwikis as below the appropriate comment lines – leaving the comments in place so that the layout is preserved when the page is edited in future. Ensure that the categories added follow the pattern [[Category:Name|{{PAGENAME}}]], otherwise they will not be sorted properly.

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

Template:Colors<noinclude>
 <!--
     PLEASE DO NOT ADD DOCUMENTATION/CATEGORIES/INTERWIKIS HERE
 -->
 {{Template doc}}
 <!--
     MAKE ADDITIONS TO THE /doc SUBPAGE INSTEAD, THANKS
 -->
 </noinclude>

This will transclude {{Template doc}} at the bottom of the template page.

Important: Make sure the opening <noinclude> begins on the same line as the last character of the template code (or text), and not on a new line. 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 Template:Tl2 on the template's talk page. If documentation, categories and interwiki links already exist in a section enclosed within a <noinclude>…</noinclude> container, move them into the documentation subpage, 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:Template doc/Preload (talk, backlinks, edit) into the editbox of the /doc subpage creation.

Extras

You can 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 Template talk:X/doc to Template talk:X.

Example

See the heavily-used Template:Cite web for an example of detailed template documentation. Note that the template itself is protected, but the documentation subpage, Template:Cite web/doc is unprotected and can still be edited.

See also

and

Personal tools
language