Help:TemplateData/fr

$extension est une extension permettant de stocker des informations au sujet d’un modèle wikitext et de ses paramètres, de manière à ce qu'une interface d'édition puisse les récupérer et les afficher dans son éditeur de modèles, rendant ainsi plus facile pour les utilisateurs l’ajout et la modification de modèles dans les pages.

Depuis avril 2019, TemplateData fait partie de l'expérience utilisateur par défaut pour tous les utilisateurs de tous les wikis de Wikimedia lorsqu'ils ajoutent un modèles, y compris les utilisateurs non enregistrés. Les éditeurs de source et visuels par défaut l'intègrent d'une manière ou une autre. Il est utilisé également dans les scripts, outils et gadgets. Si vous avez votre propre wiki, vous devrez installer Extension:TemplateData.

Ajouter TemplateData à un modèle consiste essentiellement à insérer un petit bloc de données JSON (expliqué ci-dessous) dans la page de documentation du modèle. Whilst this may sound complicated, it's rather simple. Vous avez deux façon de le faire, soit manuellement, soit en utilisant l'éditeur TemplateData, une interface graphique située dans la page de modification des modèles sur les wikis où l'extension TemplateData est installée. Les données JSON contiennent une liste de paramètres avec des informations sur chaque paramètre du modèle et le modèle lui-même. Ceux-ci sont définis ci-dessous.

Quand un modèle a des TemplateData, les informations sont affichés quand un utilisateur ajoute le modèle, parfois à la place de l'information d'origine, parfois comme information supplémentaire. Dans certains cas, cela peut changer le comportement de l'éditeur lors de la modification ou l'insertion du modèle. Cela aide les utilisateurs à identifier ce qu'ils doivent faire quand il ajoute le modèle.

Historique
À l'origine, TemplateData a été développé début 2013 pour qui était en phase de test MediaWiki à l'époque. VisualEditor est l'interface d'édition principale pour les wikis Wikimedia, et TemplateData lui permettait d'avoir une interface plus utilisable pour l'ajout de modèles. Il était officiellement supporté par VisualEditor immédiatement. Comme VisualEditor a été déployé sur les différents wikis Wikimedia majeurs en tant que fonctionnalité par défaut de 2013 à 2016, TemplateData en est également devenu une partie.

In December 2016, the VisualEditor interface was made available for editing source code as a beta feature. This was termed the 2017 wikitext editor. This brought the features of TemplateData to source editing for the first time.

En Mars 2018, Sam Wilson a développé, une extension graphique de l'éditeur de modèle pour l'éditeur de source par défaut de Wikimedia, (aussi connu comme l'éditeur wikitexte 2010), conçu pour faciliter l'ajout de modèles en utilisant les informations de TemplateData. En Avril 2019, TemplateWizard est devenu une partie par défaut de l'éditeur de wikitext 2010 sur tous les wikis Wikimedia. Cela signifiait que TemplateData faisait désormais partie par défaut de l'éditeur visuel et de l'éditeur source sur les wikis Wikimedia.

Adding or editing TemplateData
To add or edit TemplateData, first navigate to a template's page, located at "/Template:Templatename".

Prior checks
There are two things you should check before adding or editing TemplateData, in the following order:


 * 1) whether the template has a documentation subpage
 * 2) whether the template already has TemplateData and whether this is located on the template page or the documentation subpage.

Checking for the documentation subpage

The first thing to do is identify whether the template has a subpage for its documentation or not.

There are two main ways templates on most Wikimedia wikis store their usage notes and other data that shouldn't be included in the actual template itself, like categories the template should be contained in:


 * The vast majority use a documentation subpage. This is a page located at the template's name followed by "/doc". In this case, on the main template page after the template source code, there is only the text " " between  tags. Here, the Documentation template transcludes all the /doc page's content onto the template page. This makes the template's source code look much cleaner.
 * A small minority keep the information on the template's main page, after its source code. In this case, it is contained after " ", which is between  tags.

You can quickly identify whether a template has a /doc page by checking if the " Template documentation" (or similar) heading has links like "[view] [edit] [history] [purge]" after it. This may look slightly different on different wikis. Rarely, the main template page may still have documentation content even if you see these buttons and there is a /doc page. This will happen if a user has added a custom /doc page title between " " and " " then added content after " ".

A slightly more reliable way to check is by looking for the notice, "The above documentation is transcluded from Template:Templatename/doc" (or similar), in the box at the bottom of the page.

If a template doesn't have a documentation subpage

If a template doesn't have a documentation subpage, you have two options:


 * You can either create it and move its documentation (if it has any) there. After this, you can then add TemplateData to the documentation subpage. This is the preferred option.
 * Or, you can add or edit TemplateData on the main template page.

Creating the doc subpage and moving the documentation contents

On most Wikimedia wikis, you can only create a page if you are a registered user (and, at least on the English Wikipedia, have been for more than four days and have made at least ten edits).

To do this, click "Edit"/"Edit source" on the main template page, and look for the  tags and their contents, usually at the bottom.

It should look something like this:

It might also have TemplateData already. This will look something like:

Select everything after " " and before " ", cut it, then delete " ", so you are just left with:

Now, save the page.

Next, add "/doc" to the URL in the address bar after the template name, and press Enter. Then, click "Create source".

If your wiki has a Documentation subpage notice template, add it at the top. You may also want to add some other templates, like a Purge button or Purge link, if your wiki has it. See meta:Help:Template documentation for more info.

Beneath this, paste the contents of the clipboard.

Next, enclose the categories within  tags. This is so that they don't have an effect on the doc subpage, only on the template's main page.

This will look like this:

Some wikis (including the English Wikipedia) have a template. Use this if the template can be expected to have a sandbox version, located at "Template:Templatename/sandbox". It will stop the categories from having an effect on the sandbox page.

This will look like this:

After this, click "Publish page".

You can now add or edit the TemplateData on the documentation subpage based on the guidance at.

Adding or editing TemplateData on the main template page

If you do not wish to or are unable to create the /doc page, you can add or edit TemplateData on the main template page. Follow the guidance at to do this.

If a template has a documentation subpage

If a template has a documentation subpage, you should now check whether it already has TemplateData and whether this is located on the template page or the documentation subpage.

Check both the template page and the /doc subpage for the presence of TemplateData documentation; this looks something like this:

{   "description": "", "params": { "1": {           "label": "Example parameter", "description": "Example parameter description", "type": "string" }   } }

Alternatively, the TemplateData extension can perform this check for you. Simply click "Edit" or "Edit source" on either page.

If the template already has TemplateData on either page, you will see a yellow notice at the top of the page saying either:


 * "Please note: there is already a TemplateData block on the related page "Template:Templatename/doc"", or
 * "Please note: there is already a TemplateData block on the related page "Template:Templatename""

If the template has TemplateData on its documentation subpage

If the template has TemplateData on its documentation subpage, this is the page you should edit. You can do this by clicking the "[edit]" located after the heading " Template documentation" (or similar), or, if you are already on the /doc page, simply clicking "Edit" or "Edit source" at the top. Follow the guidance at to add or edit the TemplateData.

If the template has TemplateData on its main page

If the template has TemplateData on its main page, you once again have two options:


 * You can either move to its documentation subpage. This is the preferred option.
 * Or, you can edit it on the main template page.

Moving TemplateData to the documentation subpage

To do this, simply click "Edit"/"Edit source" on the main template page, and look for the  tags, enclosed within   tags. It should look something like this:

Cut only the  tags and their contents out of the code, then save the page.

Next, edit the documentation subpage by clicking the "[edit]" located after the heading " Template documentation" (or similar).

Type a heading, like "TemplateData", then beneath it paste the TemplateData.

You can now edit the TemplateData based on the guidance at.

Editing TemplateData on the main template page

If you do not wish to move the TemplateData to the /doc page, you can edit it on the main template page. See for how to edit TemplateData.

If the template does not yet have TemplateData but has a doc subpage

If the template does not yet have TemplateData, you should add it to the documentation subpage.

Do this by clicking the "[edit]" located after the heading " Template documentation" (or similar), or, if you are already on the /doc page, simply clicking "Edit" or "Edit source" at the top. Type a heading, like "TemplateData", then add it beneath this heading. The section explains how to add TemplateData.

Éditeur TemplateData
This is the simpler way to add or edit TemplateData, possible for inexperienced users.

L'éditeur TemplateData est un outil de l'extension TemplateData pour ajouter et modifier les données en utilisant une interface graphique. It is part of the TemplateData extension. Il est accessible en allant sur n'importe quel modèle (ou sous-page de documentation) et en cliquant le lien "Modifier" ou "Modifier wikicode". Après cela, vous verrez un bouton au-dessus de la zone de modification nommé "$manage".

After clicking "Edit" or "Edit source", you will see a button above the editing area and page title that says "".

Cliquer sur ce bouton permet d'entrer dans l'éditeur TemplateData. L'éditeur vous permet d'ajouter les paramètres du modèle et d'y attribuer les valeurs les plus courantes. Si la page que vous avez déjà éditée contient un bloc de TemplateData, l'information déjà documentée sera automatiquement affichée quand vous ouvrirez la page adéquate dans l'éditeur de TemplateData.

Features in the above window:


 * The top item is "Language". This item allows you to enter text content in multiple different languages, which will show depending on the language setting of the user in Preferences. It will not show depending on the language wiki, as different wikis have entirely different databases of templates. If no language TemplateData exists yet, only the language of the wiki the user is on will be available, but the user can click "Add language" to add more inputs. The language code will show in brackets next to the parameters for which it can be applied to. These include descriptions and labels.
 * The next item is the template description. This is the description of the template as a whole and is shown in various places to the user in the template editors while adding a template. This parameter and its effects are outlined here.
 * The third item is the wikitext formatting of the template. This parameter determines how the wikitext should be laid out when the user clicks "Insert", the two main types being "inline" (on one line) and "block" (on new lines). This parameter and its effects are outlined here.
 * If the user chooses "Custom", they will be able to enter a set of wikitext under "Custom format string", according to rules outlined here, to create a custom layout for the template when the user clicks "Insert".


 * The fourth item is "Template parameters". This contains a list of parameters already defined in the TemplateData, if they exist. If there are parameters stated in the template's source code for which no TemplateData exists yet, you may see a button called "Add suggested parameters". These are extracted from the template's source code by looking for  or  . Clicking "Add suggested parameters" will add these parameters under their names as defined in the source code. This will also show a green notice at the top: "2 new parameters were imported: names of parameters".
 * At the bottom is "Add parameter". This allows you to add a parameter manually with a custom name.

The next stage is clicking any one of the parameters in the list. This will allow you to edit that parameter's info.



All of these features and their effects are outlined at #Within a parameter's name.

When you are finished, click "Apply". This will automatically insert the TemplateData at the bottom of the page before the tag; or, if it already exists, it will update it with the new information without changing its position at all. The TemplateData text will also be selected when you click "Apply".

The TemplateData editor creates a  parameter at the bottom of the TemplateData or updates it if it already exists. This contains the current TemplateData parameters in the order they were displayed in the TemplateData editor. You can change the paramOrder by dragging the parameters in different orders in the TemplateData editor using the three horizontal bars on the left. and its effects are outlined here.

After this, click "Save" to save the revision of the page.

Manual method
The alternative is to add or edit TemplateData manually. You may need or wish to do this in some cases. La structure des TemplateData est basée sur le standard JSON. Notez que toutes les descriptions dans un TemplateData doivent être en texte brut (pas de wikitexte, pas de liens, etc.). It follows a few very simple rules and takes only a few dozen possible predefined parameters and values, almost always in a  format.

Adding TemplateData manually

Preconsiderations:


 * If you're adding TemplateData on a template's documentation subpage, you may add it anywhere on the page; check to see if your language's Wikipedia has a preferred location for it. For example, on the English Wikipedia, TemplateData is typically near the bottom of the documentation page; on the German Wikipedia, it is typically at the top.
 * If you're adding TemplateData on a template's main page (which is not preferred; see #Prior checks), you must make sure that it is within the  tags.

First, click "Edit" or "Edit source" on the respective page, then go to the position you are adding the TemplateData and write a heading like "TemplateData".

Many wikis (but not all) have a TemplateData header template, which adds a short notice about the TemplateData. If yours does, add this after the heading.

To start adding the TemplateData, type an opening and closing  tag and a pair of curly brackets on new lines, with an empty line between them:

Next, add an indent on the empty line between the two curly brackets, and start adding parameters. Details for the parameters can be found at. Most are optional, but some are highly recommended.

Parameters can be in any order, but the order that will best correlate with what shows in the TemplateData documentation and contribute to ease of use for editors is the following:

L'ordre des paramètres n'affecte pas le fonctionnement, tant que, ceux à l'intérieur, par exemple de l'objet #Unexpected property restent dans l'objet.

 === Exemple === 

Here is some example TemplateData for a hypothetical cleanup template. The template would display a notice, and its source code would be programmed to place the page into a dated category based on the month and year entered. The notice could also contain a link to a talk page section, if specified. The TemplateData would look something like this:

The corresponding TemplateData documentation would display as the following:

{	"description": "Use this template to indicate that an article is in need of cleanup.", "format": "inline", "params": { "date": { "label": "Month and year", "description": "The month and year that the template was added", "type": "string", "autovalue": " ", "example": "January 2013", "suggested": true },		"reason": { "aliases": ["1"], "label": "Reason", "description": "The reason the article is in need of cleanup", "type": "string" },		"talk": { "aliases": ["talksection"], "label": "Talk page section", "description": "The section of the talk page containing relevant discussion", "type": "string" }	},	"paramOrder": [ "date", "reason", "talk" ] }

Description et paramètres
Chaque paramètre de TemplateData est listé ci-dessous avec une description et un exemple. Ils sont également listés sur Extension:TemplateData#Format.

Within a parameter's name
Note: if neither "required", "suggested" nor "deprecated" are set as true for a parameter, its status will show as "optional" in the TemplateData documentation.

Une fois que vous avez fini, cliquez sur « Enregistrer ». Si vous avez fait des erreurs, vous ne pourrez pas enregistrer (ce qui peut être troublant, mais garantit que vous ne pouvez rien casser). Si vous avez des erreurs, vous pouvez expliquer sur la page des retours ce que vous avez essayé de faire, et nous serons heureux de vous aider.

Signalons que si vous abusez d’un modèle astucieux pour générer dynamiquement les TemplateData, il ne pourra pas y avoir de vérification des erreurs avant la sauvegarde.

Notez que chaque information est entourée par des guillemets droits (") (sauf pour  et  ), et séparée de la suivante par une virgule (sauf pour la dernière).

Type parameter
Le paramètre  signale à l'éditeur de modèles la nature de la valeur d'un paramètre. In some cases, template editors have been programmed to modify the user interface for a certain parameter according to this TemplateData value, such as to only allow the user to enter valid values that match the specified type. This parameter does not have any functional effect on the template parameter or its value; it merely controls how template editors see and treat the parameter in editing mode.

How to use

It is used by adding the  parameter, followed by a colon and a space, then adding any of the values listed in the table below in speech marks.

Example:

Effects

As of February 2020, only 5 of the 13 type values have visible effects in VisualEditor and the 2017 wikitext editor, while 8 have visible effects in TemplateWizard.

The effects of certain values are likely to change as the template editors get updates to support them. One such effort for VisualEditor and the 2017 wikitext editor is tracked in the Phabricator task T55613. A similar effort to get TemplateWizard to support the boolean value is tracked in T200664.

The currently known effects are listed as follows.

Formats personnalisés
When editing the  value, you create custom formats by inputting a set of wikitext symbols using some predefined rules.


 * - start of the template
 * - content (e.g., string, integer or parameter). This underscore serves to indicate the minimum length of a value in characters and can be repeated, like . If this length is not reached, it fills the remaining characters with spaces. This can be used to align all equals signs to a specific position after a parameter (if used with   for new lines).
 * - pipe (separates parameters)
 * - equals sign (precedes the value of a parameter)
 * or pressing the enter key - new line (this will display as  in the entry field)
 * - space (can be used with  to indent new lines)
 * - end of the template

The wikitext should at least meet the minimum of, otherwise there will be an invalid format string error.

Structure vierge
Vous pouvez copier la structure vierge ci-dessous pour ajouter un nouveau TemplateData à un modèle. Seules les étiquettes les plus courantes sont présentes.

« Syntax Error in JSON » et « Bad JSON format »
Néanmoins, si vous essayez de sauvegarder cette page avec un éditeur basé sur le JavaScript, tel que l' Editeur visuel ou l'éditeur Wikitext 2017, vous aurez un message d'erreur « Syntax error in JSON » parce que l'analyseur JavaScript est plus sévère et n'autorise pas le JSON non valide.

En plus, si vous essayez d'ouvrir ce JSON non valide avec l'éditeur graphique de données de modèle, vous verrez le message d'erreur « Bad JSON format ».

This error can come up quite frequently while editing a template's TemplateData. The most common mistakes that cause this error include excess commas (such as trailing commas), missing commas and missing quotation marks.


 * Examples of trailing commas:


 * Examples of missing commas:


 * Example of missing quotation marks:

Pour corriger ces erreurs, vous pouvez mettre le bloc JSON dans un valideur JSON externe tel que JSONLint et cela mettra en surbrillance les virgules et les clés qui posent problème, pour que vous puissiez les supprimer.

en raison d'un bogue qui était déjà là depuis longtemps, les utilisateurs de l'ancien éditeur de code wiki pouvaient sauvegarder des pages contenant certains types JSON non valides, tels que les clés dupliquées ou les virgules ',' à la fin du texte (voir ).

Required property "paramOrder(number)" not found.
This error occurs if you state a parameter in  that is not stated in. The number in the square brackets refers to the parameter in  that is missing. It refers to its order in the sequence, but it is one less than its actual position, since  is an array; 0 is the first one, 1 is the second, etc.

To fix this, make sure all parameters stated in  are listed in. Alternatively, you can remove the  object to remove this error.

Invalid value for property "paramOrder(number)".
This error occurs if you state a parameter in  that is not stated in. The number in the square brackets refers to the parameter in  that shouldn't be there. It refers to its order in the sequence, but it is one less than its actual position, since  is an array; 0 is the first one, 1 is the second, etc.

To fix this, make sure all parameters stated in  are listed in. Alternatively, you can remove the  object to remove this error.

Property "params.parametername.required" is expected to be of type "boolean".
This error occurs if you put quotation marks around the value of either  or.

These are boolean values, not strings, therefore they require no quotation marks. To fix this, remove any quotation marks around the values  or   for these parameters.

Property "format" is expected to be ...
If the  parameter exists but its value is not ,   or a valid format string, you will see the error message "Property "format" is expected to be "inline", "block", or a valid format string."

To fix this, make sure the value after  equals   or   and that there no spelling mistakes. Alternatively, if it's wikitext, make sure it contains a minimum of  and that there are no mistakes in the syntax that would normally cause a template to fail, such as duplicate equals signs or missing/duplicate curly brackets; see the section #Custom formats for the syntax for custom formats. Alternatively, you can remove the  parameter to remove this error.

Unexpected property "parametername".
This error occurs if you state a parameter that does not exist in TemplateData. This is probably due to spelling mistakes.

It also occurs if you state a parameter in any TemplateData object that is not a parameter of that object. This may be due to spelling mistakes, or you may have written the parameter of one TemplateData object under another object that it doesn't belong to.

For example, you might have written the parameter  under the root TemplateData object instead of inside  :

Alternatively, if the unexpected parameter is under a template parameter inside, you'll see its name after "params.parametername." in the error.

To fix this, make sure there aren't any spelling mistakes in the parameter names, and make sure your parameters are in their correct location. Additionally, make sure you don't state any parameters that don't exist for a TemplateData object. You can check which parameters exist for an object in the section #TemplateData parameters.

Required property "params" not found.
Cette erreur (Propriété "params" demandée mais non trouvée) apparaît quand il n'existe pas d'objet  dans les TemplateData. This is a necessary object, as it contains all the details of each parameter, so to fix this error, make sure it's added and that there are no spelling mistakes. Voir la section ci-dessus sur la manière d'ajouter le paramètre.

Limitations et avis

 * Fonctionnalités manquantes – TemplateData est vraiment un exemple d’outil qui a été créé avec de peu de fonctionnalités, dans l’espoir que les utilisateurs aideraient à guider le développement de fonctionnalités telles qu’ils le désirent. Si vous voulez demander de nouvelles fonctionnalités pour TemplateData, faites-le-nous savoir.
 * Retards pour l'affichage dans les modèles – Après que TemplateData a été ajouté à un modèle, les métadonnées devraient être visibles immédiatement lorsque le modèle est ouvert dans l’éditeur visuel. Toutefois, il est possible que cela prenne plusieurs heures avant que les métadonnées ne soient affichées. Vous pouvez forcer la mise à jour en faisant une modification vide sur la page du modèle lui-même (pas la sous-page de documentation). Pour faire une modification vide, ouvrez la page du modèle en édition et enregistrez la page sans faire aucun changement ni ajouter de résumé de modification.
 * Problèmes en cours – Une liste des bogues actuels et des demandes de fonctionnalités est disponible sur le gestionnaire de bugs Wikimedia.

Autres outils

 * : Une fenêtre de dialogue de la barre d'outils pour entrer le code wiki du modèle via un formulaire construit à partir de TemplateData.
 * TemplateData Wizard: Un outil qui génère un TemplateData grâce à une interface interactive.
 * Skeleton TemplateData generator: Un outil qui lit le wikicode source d’un modèle, essaye de trouver tous les paramètres utilisés et donne un squelette avec les paramètres listés.
 * JSONLint: Un outil qui vous permet de valider un JSON écrit à la main pour trouver les erreurs dans la syntaxe.
 * Liste de tous les modèles avec TemplateData sur ce wiki
 * Sur la version allemande de Wikipédia, avec le modèle TemplateData, les template data sont affichées dans une boîte de dialogue, et le modèle est ajouté dans une catégorie des modèles ayant des template data.