Template:Documentation/doc

This is the Documentation template.

For most of the instructions about how and when to use this template, see Template documentation.

This template displays a green doc box like you are seeing now, and automatically loads the content from a /doc subpage. It can also load the content from other places if instructed to.

This template is intended for documenting templates and other pages which are transcluded onto other pages. It can be used in template space and most other namespaces.

Use of this template allows templates to be protected where necessary, while allowing anyone to edit the documentation and categories.

Usage
Normally this template is used without any parameters, placed at the bottom of the template or page being documented, within :

Then this template automatically loads the content from the /doc subpage of the template it is used on.

This template can also load the content from any other page. Like this:

Note that when loading the documentation from a page other than the local /doc page it becomes tricky to handle the categories.

The content can also be fed directly as text. Like this:

When the content parameter is used, the doc box normally does not show the [edit] [purge] links in the top right corner. Note that if the /doc page exists, a link to it is still shown in the link box below the doc box.

Parameter 1 and the content parameter can also be combined, like this:

Then the pagename fed as parameter 1 is used for the [edit] [purge] links and for the /doc link in the link box below the doc box. But the content parameter is used for the content shown in the doc box. The above code means that the content is transcluded as. In this example a parameter is also fed to the /doc page being loaded.

Best practice
The code should be added at the bottom of the template code, with no space before (which would cause extra space on pages where the template is used).

Categories that apply to the template itself should be added to the bottom of the /doc subpage, inside  tags. Interwiki links that apply to the template should be listed at Wikidata (more at Wikidata). For more complex cases, see Template documentation.

If the documentation page contains or  tags as part of the visible documentation text, replace the " " with " ".

The heading
When in the Template namespace, this template shows this heading:
 * Template-info.png Template documentation

In most other namespaces, such as "Wikipedia:", it shows this heading:
 * Documentation

But when on File (image) pages it shows this heading:
 * Summary

The heading parameter can be used to set the heading to something else. Like this:



If the heading parameter is empty but defined, no heading is shown and no [edit] [purge] links are shown. Like this:



The heading-style parameter can be fed optional CSS values. Without quotation marks  but with the ending semicolons. For example:

The link box
Below the big doc box is a small link box that shows some meta-data about the documentation. The link box shows different things depending on what parameters are fed to this template, and in which namespace it is used. In some cases the link box is not shown at all.

To hide the link box, add the parameter off.

You can also insert customised text in the link box, by defining the link box parameter. For example: This documentation is automatically generated by [ [Template:Country showdata]]|undefined

Automatic functions
If the documentation page does not exist, the [create] link includes a preload page so that clicking it will pre-fill the edit form with the basic documentation page format. Preload text is also used for the /sandbox and /testcases (create) links.

When this template is on a protected template page it now automatically adds pp-template which shows the grey or red padlock in the top right corner. So no need to manually add to templates that use Documentation.

When this template is on a /sandbox subpage it automatically adds the Template sandbox notice.

Subject namespaces vs. talk namespaces
Terminology: Subject namespaces are the opposite of talk namespaces. For instance "Template:" is the subject space of "Template talk:".

This template is usually placed in a subject namespace, within tags. But in some cases this template needs to be on the talk page:


 * In the Mediawiki namespace, since often does not work in system messages, and since the Mediawiki namespace needs to be kept clean for performance reasons.

When placed on talk pages, this template usually is placed near the top of the page and without  tags.

The /doc, /sandbox and /testcases pages should normally be in the subject namespace, except in the namespaces that do not have the MediaWiki subpage feature enabled: Main, File, Mediawiki and Category. (But currently we only show the /sandbox and /testcases links from User, User talk, Template and Template talk namespaces.) There are also a whole bunch of other technical reasons why the /doc page must be stored under the talk page for those (but only those) namespaces.

This template automatically points its [create] links for the /doc, /sandbox and /testcases to the right namespace.

Testing
You can simulate the output for a given page by using the page parameter. For example, if you use the code Template:Edit protected, the template will behave exactly as if it were on the page Template:Edit protected, including showing the documentation from Template:Edit protected/doc, linking to Template:Edit protected/sandbox, etc. This parameter is useful for testing, and is used extensively on the module test cases page.

Technical details
This template calls Documentation/start box2 and Documentation/end box2 which in turn call Documentation/start box and documentation/end box. The /start box (and /end box) hold most of the code, while this template and /start box2 (and /end box2) do parameter preprocessing.

The preload page for the /doc [create] link is Template:Documentation/preload. The preload pages for the /sandbox and /testcases [create] links are Template:Documentation/preload-sandbox and Template:Documentation/preload-testcases.

For more technical details see the talk page.