Jump to content

Wikipedia:TemplateData

From Wikipedia!

Template:Policy shortcut

TemplateData is a system on Wikipedia and other MediaWiki-based sites for storing machine‑readable documentation about a wikitext template. It records information such as parameter names, aliases, whether a parameter is required or suggested, default values and descriptions, so that editing tools like VisualEditor and the 2017 wikitext editor can offer users context‑aware forms instead of raw template syntax.[1][2]

Without TemplateData, editors must remember or look up the names and meanings of template parameters. With TemplateData, this information is attached directly to the template or its documentation subpage in a JSON‑like block, and tools can read it to build a user interface for filling in parameters correctly.[3]

What is TemplateData?

[edit]

TemplateData is metadata about a template written in a specific JSON‑style structure placed on the template page or, more commonly, on its /doc subpage. The TemplateData block typically describes:

  • A short description of what the template does (the description field).
  • A list of parameters, each with:
    • A label and internal name.
    • Whether the parameter is required, optional or suggested.
    • A description for editors.
    • Possible or suggested values.
    • Whether the parameter is deprecated.
  • Information about which parameter is used for inline content (e.g. for citation templates).[2]

Editing interfaces such as VisualEditor read this structure and present a form where each parameter appears as a labelled field with help text. This reduces syntax errors and makes complex templates easier for new editors to use.[4]

Editing without TemplateData

[edit]

When a template does not have TemplateData, VisualEditor either shows a plain, unstructured dialog or falls back to a single text box representing the unnamed content of the template. Editors then have to look at the template code, its documentation, or examples in other articles to guess the parameter names and their expected values.[1]

This often leads to:

  • Typos in parameter names (which may silently break formatting).
  • Use of deprecated or undocumented parameters.
  • Empty parameters being left in articles.
  • Frustration for editors not familiar with template syntax.

Editing with TemplateData

[edit]

When TemplateData is defined, VisualEditor and other tools can:

  • Show a list of available parameters with human‑readable labels.
  • Indicate which parameters are required or suggested.
  • Provide descriptions and help text next to each field.
  • Offer drop‑down lists or suggested values where appropriate.
  • Hide deprecated or advanced parameters unless specifically requested.[3][2]

For example, for an infobox template, TemplateData allows the editor to see “Date of birth” instead of remembering the internal parameter name such as |birth_date=.

Adding TemplateData

[edit]

Where to place TemplateData

[edit]

TemplateData can be added either:

  • Directly on the template page (e.g. Template:Infobox person), or
  • On the documentation subpage (e.g. Template:Infobox person/doc).

On Wikipedia, it is usually preferred to store TemplateData on the /doc subpage, together with the usage instructions and examples. This keeps the template code itself clean and improves maintainability.[1]

The TemplateData block is placed inside a <templatedata>...</templatedata> tag so that MediaWiki and editing tools can recognise and parse it, while the JSON‑like content is not rendered to readers.

Basic structure

[edit]

A minimal TemplateData block looks like this:

<templatedata> {

 "description": "Short description of what the template does.",
 "params": {
   "example": {
     "label": "Example parameter",
     "description": "An example parameter.",
     "type": "string",
     "required": false
   }
 }

} </templatedata>

The top‑level object usually contains at least the keys description and params. Each parameter within params is itself an object with several supported properties such as label, description, type, required and deprecated.[2]

Adding suggested values

[edit]

TemplateData supports suggested values for parameters via the suggestedvalues property. Tools can show these values as a drop‑down menu or as autocomplete suggestions, which is particularly useful for parameters that expect one of a small set of fixed strings (such as date formats, access types in citation templates, or layout options in infoboxes).[3]

For example:

<templatedata> {

 "description": "Example template with suggested values.",
 "params": {
   "access": {
     "label": "Access level",
     "description": "How the material can be accessed.",
     "type": "string",
     "suggestedvalues": ["free", "subscription", "registration"],
     "required": false
   }
 }

} </templatedata>

Tools and interfaces

[edit]

TemplateData is primarily consumed by:

  • VisualEditor – to build template dialogs, list parameters and provide help text.
  • The 2017 wikitext editor – to provide similar structured forms for templates.
  • API clients and bots – which can query TemplateData to help with mass editing and template migration tasks.[2][4]

On Wikipedia, editors can view and edit TemplateData through a dedicated interface. When editing a template or its documentation, a “TemplateData” button opens a visual editor for the metadata, allowing parameters to be added, reordered and described without having to manually edit the JSON structure.

Best practices

[edit]

Pages in the TemplateData guideline recommend that template maintainers:

  • Document all commonly used parameters, including aliases.
  • Mark parameters as required only when truly necessary.
  • Provide concise but clear descriptions to help new editors.
  • Use human‑readable labels rather than internal code names.
  • Keep TemplateData in sync with the template’s actual implementation.
  • Avoid documenting obsolete parameters unless they are needed for backwards compatibility.[1][3]

Consistent TemplateData across templates makes it easier for editors to move between different infoboxes, citation templates and navigation boxes, since the user interface follows the same general pattern.

See also

[edit]

References

[edit]
  1. ^ a b c d "Wikipedia:TemplateData". Wikipedia. Wikimedia Foundation. Retrieved 2025-12-13.
  2. ^ a b c d e "Help:TemplateData". MediaWiki.org. Wikimedia Foundation. Retrieved 2025-12-13.
  3. ^ a b c d "Wikipedia:TemplateData/Tutorial". Wikipedia. Wikimedia Foundation. Retrieved 2025-12-13.
  4. ^ a b "TemplateData and VisualEditor". MediaWiki.org. Wikimedia Foundation. Retrieved 2025-12-13.