The TemplateData extension introduces a <templatedata> tag and an API which together allow editors to specify how templates should be invoked.
This information is available as a nicely-formatted table for end-users, and as a JSON API, which enables other systems (e.g. VisualEditor) to build interfaces for working with templates and their parameters.
See Help:TemplateData#Custom formats for in-depth help.

Installation

Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

To users running MediaWiki 1.24 or earlier:

The instructions above describe the new way of installing this extension using wfLoadExtension() If you need to install this extension on these earlier versions (MediaWiki 1.24 and earlier), instead of wfLoadExtension('TemplateData');, you need to use:

require_once"$IP/extensions/TemplateData/TemplateData.php";

Redigering af data

The TemplateData extension works through having a <templatedata> tag defined in the wikitext of a template page (optionally it can be transcluded from a different page as well).
This is designed to be compatible with the common layout many wikis have of transcluding template documentation from a separate page (but is not required).
This content of the <templatedata> tag must be valid JSON using the format described below; note that all descriptions must be in plain text (no wikitext is accepted inside the template data).

When a <templatedata> block is included on a page, the TemplateData extension performs the following checks when the page is being saved:

Indholdet skal være gyldigt JSON;

Each item within the JSON structure must be of the expected type as specified below (e.g. object, array, or a primitive); and

For those items which have a specified list of possible values (e.g. params.yourParameterName.type), the value in the JSON object must match one of those values.

If any of these checks fails, the server will not be permitted saving and an error message will be displayed above the edit page.

For autovalue items, bug 2700 prevents subst: from working in any template that is added inside a <tag>, including <ref> and <gallery> tags.
The TemplateData block will save correctly, but the resulting wikitext will not be parsed correctly when the template is used.

Note that you cannot use {{#tag:templatedata}} in lieu of <templatedata>.

Format

The below is a visualised version of the JSON data as defined on the template page enclosed by <templatedata></templatedata> tags. The formal specification is available in the TemplateData repository. Refer to Specification.md for the latest version.

TemplateData object

The TemplateData object is a JSON root element enclosed in a <templatedata> element on the template page.

A brief description of the template. It must be in plain text. Once filled, it can be displayed as caption when editing a single template and perhaps in search results when users pick one of many. The default is null.

An object that maps each parameter name of the template to a corresponding Param object describing the properties of that parameter.

paramOrder

Array containing parameter name strings

The logical order in which parameters should be displayed. The array contains each parameter key exactly once. Each string must be a valid key in the params object. If this key does not exist in the <templatedata></templatedata> structure on the template page, it is added to the structure provided by the API using the order in which the parameters occur within the TemplateData object.

An object that maps a simplified name of a third party consumer of the template data (i.e. Citoid, Wikidata, etc.) to an object that in turn maps a name of a consumer parameter to one or more corresponding names of template parameters.

Param object

A brief description of the parameter, for users to know which to pick from an option list.

required

boolean

false

Whether the parameter is required for the template to work (true if this parameter must be specified).

suggested

boolean

false

Whether the parameter is suggested for the template to be useful (true if this parameter should be specified).

deprecated

boolean or string

false

Whether the parameter is deprecated; this can be a string of instructions for the user detailing what instead the user can do, or be simply true.

aliases

Array containing strings

[]

List of aliases. An alias is an alternative name for the parameter that may be used instead of (not in addition to) the primary name. Aliases are not documented in a separate Parameter object. If they need more information, they should be in their own property marked "deprecated".

A date in ISO 8601 format, e.g. "2014-05-09" or "2014-05-09T16:01:12Z"

"wiki-page-name"

A valid MediaWiki page name for the current wiki. Doesn't have to exist, but if not, should be a valid page name which could be created.

"wiki-file-name"

A valid MediaWiki file name for the current wiki. Doesn't have to exist, but if not, should be a valid file name which could be uploaded. Should not include the namespace (e.g. "Foo.svg" not "File:Foo.svg" or "Bild:Foo.svg").

"wiki-template-name"

A valid MediaWiki Template name for the current wiki.

"wiki-user-name"

A valid MediaWiki user name for the current wiki. Doesn't have to exist, but if not, should be a valid user name which could be created. Should not include the namespace (e.g. "Foo" not "User:Foo" or "Usario:Foo").

"content"

Page content in wikitext, such as text style, links, images, etc.

"unbalanced-wikitext"

Raw wikitext that should not be treated as standalone content because it is unbalanced - for example, templates concatenating incomplete wikitext as a bigger whole, such as {{echo|before=<u>|after=</u>}}

inherits

string

none substituted

The name key of another parameter (must be a valid key in the params object). The current Parameter Object will inherit properties from the specified Parameter Object, with local properties overriding the inherited ones.

Set object

A (very) brief name for the parameter set. Try to keep under 20-ish characters.

params

Array of strings

One or more names of parameters to include in the set (each must be a valid key in the params object). A parameter may be in multiple sets. Not every parameter must be in a set.

Maps object

Key

Type

Default

Description

name of consumer

object

{}

An object that maps a name of a consumer to an object that in turn maps a name of a consumer parameter to one or more corresponding names of template parameters.

The names of the template parameters can be specified either as a string (one name), an array of strings (several names), or an array of arrays of strings (several sets of names); each of these strings must be a valid key in the params object elsewhere in the same template's TemplateData.

A specific template parameter may be in multiple maps, and it may be used in the values of multiple keys in a given map, but not every template parameter must be in a map.

A shortened example from English Wikipedia's Template:Cite news illustrates the structure of a maps object:

Object type

Localized string for use on the Wikipedia corresponding to the given language code.

Example of object mapping:

Key

Value

"en"

"Welcome to Wikipedia"

"de"

"Willkommen bei Wikipedia"

"fe"

"Bienvenue sur Wikipédia"

"nl"

"Welkom op Wikipedia"

"it"

"Benvenuti su Wikipedia"

"es"

"Bienvenidos a Wikipedia"

"ru"

"Добро пожаловать в Википедию"

Example

An example TemplateData structure as specified within wikitext on a template page.

<templatedata>{"description":"Label unsigned comments in a conversation.","params":{"user":{"label":"User's name","type":"wiki-user-name","required":true,"description":"User name of person who forgot to sign their comment.","aliases":["1"]},"date":{"label":"Date","suggested":true,"description":{"en":"Timestamp of when the comment was posted, in YYYY-MM-DD format."},"aliases":["2"],"autovalue":"{{subst:#time:Y-m-d}}"},"year":{"label":"Year","type":"number"},"month":{"label":"Month","inherits":"year"},"day":{"label":"Day","inherits":"year"},"comment":{"required":false}},"sets":[{"label":"Date","params":["year","month","day"]}],"maps":{"ExampleConsumer":{"foo":"user","bar":["year","month","day"],"quux":["date",["day","month"],["month","year"],"year"]}}}</templatedata>

Below is how the above example would be displayed on the template page:

Additions and changes to JSON as received from the API

The JSON structure provided in response to an API HTTP get request is significantly different than that which is defined in the <templatedata>...</templatedata> block. In response to the API request, extension TemplateData makes the following changes to the JSON object:

The TemplateData Object containing the information payload. The key is a static page number for the template page from which the JSON data was requested.

TemplateData Object (added by API)The following key is added to the root of the JSON object which is enclosed in <templatedata> tags on the template page.

Key

Type

Default

Description

title

string

The page name of the template (e.g. "Template:Cite web"). This key is not contained in the JSON structure on the template page. It is added to the structure by the MediaWiki software in route to delivery via the API.

paramOrder

Array containing parameter name strings

The logical order in which parameters should be displayed. The array contains each parameter key exactly once. Each string must be a valid key in the params object. If this does not exist in the <templatedata></templatedata> structure on the template page, it is added to the structure as provided by the API using the order in which the parameters occur within the TemplateData object.

An array containing set specifications. A set is a group of parameters that should be used together. If this does not exist on the template page it is added as an empty array to the structure provided by the API.

If defined as a string, converted to a InterfaceText object. If not defined, key is added with a null value.

deprecated

boolean or string

If not defined, default value of false added.

aliases

Array of strings

If not defined, a default empty array is assigned (i.e. [] ).

default

string

If not defined, default of "" is assigned.

type

string

If not defined, default of "unknown" is assigned.

inherits

removed

This key is removed and all inherited keys are added. Keys defined for the current parameter take precedence and any keys not defined on either the current param, or the one from which it inherits are given the default value.

Object (containing localized strings by Wikipedia language code)If a TemplateData field on the template page contains a string, not an object with localized strings, MediaWiki translates it into an InterfaceText Object with a string assigned to the key name of the source Wikipedia Wikipedia language code. The default for all InterfaceText fields is null.

See also

This extension is being used on one or more Wikimedia projects. This probably means that the extension is stable and works well enough to be used by such high-traffic websites. Look for this extension's name in Wikimedia's CommonSettings.php and InitialiseSettings.php configuration files to see where it's installed. A full list of the extensions installed on a particular wiki can be seen on the wiki's Special:Version page.