Changes

Jump to: navigation, search

Help:Template documentation

6,161 bytes added, 23:22, 12 July 2006
Template talk page: documentatation isn't right either
{{h:h}}[[Category:Editor handbook]]
There are several ways to document what a template is supposed to do:
# In some cases it is obvious on the template page itself without special provisions.
# It can be explained in <code>&lt;noinclude&gt;</code>''text''<code>&lt;/noinclude&gt;</code>.
#:This method allows to add the template to a template [[Help:category|category]].
# A detailed documentation can be put on the '''template talk''' page.
#:This method is typically mixed with the noinclude-strategy on the template page, with a reference to the talk page, and perhaps a summary.

== On the template page ==
The [[Help:template|template]] page serves two purposes: defining its working when included in another page, and producing a rendered page providing information. The parts not in noinclude tags define the template for the system. The parts of the wikitext not in includeonly tags are rendered on the template page. With the two types of tag pairs the template page can be used for definition ''and'' documentation.

A typical template page could contain:

<nowiki><includeonly></nowiki><nowiki><!--</nowiki>''template name''<nowiki>--></nowiki>''definition content, possibly a tag for a category of pages that include the template''<nowiki></includeonly><noinclude><</nowiki>nowiki>''definition content, possibly formatted, annotated, summarized''<nowiki><</nowiki>/nowiki>''further explanation, tags for template categories (using the sortkey <nowiki>{{PAGENAME}}</nowiki>)''<nowiki></noinclude></nowiki>

The template name within comment tags is useful in the case of substitution.

For example, for {{tim|t}}:

<nowiki><includeonly>start-{{{1|pqr}}}-end</includeonly><noinclude><</nowiki>nowiki>start-<nowiki>{{{1|pqr}}}-end<</nowiki>/nowiki>[[Category:Demo template]]<nowiki>[[Category:Demo template]]</noinclude></nowiki>

This renders as:

:<includeonly>start-{{{1|pqr}}}-end</includeonly><noinclude><nowiki>start-{{{1|pqr}}}-end</nowiki></noinclude>

while without tags part of the information about the content would not be displayed:

:start-{{{1|pqr}}}-end

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:

start-<nowiki><includeonly>{{{1|pqr}}}</includeonly><noinclude><</nowiki>nowiki><nowiki>{{{1|pqr}}}<</nowiki>/nowiki><nowiki>[[Category:Demo template]]</noinclude></nowiki>-end

again rendered as:

:start-<includeonly>{{{1|pqr}}}</includeonly><noinclude><nowiki>{{{1|pqr}}}</nowiki></noinclude>-end

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

===Table===
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.

===Rendering===
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:
*<nowiki>#</nowiki>expr applied to an expression with a parameter gives "Expression error: unrecognised punctuation character "{"".
*a variable is rendered as its value.

The [[Help:parameter default|parameter default]] mechanism can also be used to document what a paramter typically does:
*An undefined <nowiki>{{{1}}}</nowiki> is rendered as <nowiki>{{{1}}}</nowiki>, clearly indicating that the template expects to get a first parameter.
*An undefined <nowiki>{{{1|}}}</nowiki> displays nothing, that's probably the desired effect, but not helpful for a self-documentating template.
*Maybe it's possible to indicate the function of an expected parameter, e.g. <nowiki>{{{1|image}}}</nowiki> for templates doing something with images.

Typically, examples in the noinclude-part include or [[Help:substitution|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 [[Help:Show preview|preview]] and, in the case of substitution, in "show changes".

===Category===
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''&lt;includeonly&gt;[&#91;Category:''target''&#93;]
&lt;/includeonly&gt;&lt;noinclude&gt;
''documentation and/or link to talk page''
[&#91;Category:''tempcat''|{&#123;PAGENAME&#125;}&#93;]
&lt;/noinclude&gt;
Here ''target'' means a category for pages using the template, and
''tempcat'' 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
<tt>[&#91;Category:''target''&#93;]</tt> by
<tt><nowiki>{{{category|[[Category:</nowiki>''target''<nowiki>]]}}}</nowiki></tt>.
Normally the dummy parameter <tt><nowiki>{{{category}}}</nowiki></tt> is undefined (unused),
and then the template adds pages to category ''target'' as before. Setting <tt>category=</tt>
(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.

==Template talk page==

In addition, the template ''talk'' page can be used to explain the template and its parameters. Preferably examples are given of template calls (put them in nowiki tags) and the results (put the template call without nowiki tags in the wikitext). In complicated cases, [[Help:substitution|substitution]] can be very helpful in the explanation to demonstrate the working.

The talk page of course still offers to discuss the template after its documentation.

== See also ==
* {{tim|Template documentation}}
* {{tiw|en|Template documentation}}
* {{tim|doctl}}
* {{tiw|en|doctl}}

{{h:f|enname=Template documentation}}
Anonymous user

Navigation menu