Aide:Documentation des modèles

This page is a translated version of the page Help:Template documentation and the translation is 27% complete.

Manuel de MediaWiki : I. LecteursII. ÉditeursIII. Administrateurs

Index | Guide pour le manuel | Principes éditoriaux | MediaWiki | +/-

Cette page d'aide concerne la manière de documenter les modèles. L'aide générale concernant les modèles se trouve sur ici.

Vous avez plusieurs manières de documenter la fonction d'un modèle :

  1. In some cases it is obvious on the template page itself without special provisions.
  2. It can be explained in <noinclude>...</noinclude> tags.
    This method allows for such things as adding the template to a template category.
  3. 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.

Sur la page du modèle

The include-part of the template page defines the way it works when transcluded or substituted, while the non-includeonly parts produce the page itself.

A typical template page could contain:

<includeonly><!--template name-->
definition content, possibly a tag for a category of pages that include the template</includeonly><noinclude>
<nowiki><translate nowrap><!--T:14--> definition content, possibly formatted, annotated, summarized</translate></nowiki>

explanation, examples, and tags for template categories (using the sortkey {{PAGENAME}})
</noinclude>

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

For example, for Template:T:

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

This renders as:

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

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

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

again rendered as:

start-{{{1|pqr}}}-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.

Rendu

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

Catégorie

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:

...fin du code<includeonly>[[Category:cible]]
</includeonly><noinclude>
documentation et / ou lien vers la page de discussion
[[Category:catégorie du modèle|{{PAGENAME}}]]
</noinclude>

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.

Exemples

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.

Voir aussi


Consultation : Bouton consulter | Recherche | URL | Espace de noms | Nom de page | Section | Lien | Pages liées | Lien redirigé | Lien interwiki | Redirection | Catégorie | Page spéciale

Suivre les modifications : Modifications récentes | (améliorées) | Suivi des liens | Liste de suivi | Historique | Différences | Contributions | Résumé des modifications | Modification mineure | Modifications surveillées

Inscription et préférences : Enregistrement | Préférences | Personnalisation

Édition : Édition | Syntaxe wiki | Démarrer une page | Images et fichiers | Page d'image | Caractères spéciaux | Formules | Tableaux | Listes | Frise chronologique | Boîte d'entrée | Modèle | Renommer une page | Raccourcis d'édition | Éditeurs externes | Page de discussion | Tester | Export | Import |

Toutes les pages d'aide sur : Meta | Wikipédia | SdL

modifier ce cadre

Other languages: