This document specifies the structure that TemplateData blobs must follow.
The key words "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC 2119](http://tools.ietf.org/html/rfc2119).
## 2 Terminology
### 2.1 Template
A page on a MediaWiki website that can be transcluded into other pages. Refer to [mediawiki.org](https://www.mediawiki.org/wiki/Help:Templates) for documentation about what templates are capable of and how to create or use them.
### 2.2 Parameter
A key–value pair associated with the transclusion of a template in order to alter the behaviour of a template (and by extend, the content it will return as part of the transclusion).
### 2.3 Author
A program that creates and modifies TemplateData blobs, and distributes them to TemplateData consumer programs.
### 2.4 Consumer
A program interpreting TemplateData blobs (supplied by a TemplateData author).
### 2.5 User
A person using a TemplateData consumer program.
## 3 Structures
Authors MUST ensure TemplateData blobs have exactly one top-most structure of key–value pairs (hereafter referred to as "objects" having "properties") that follow the specification for the "Root" structure, as specified in section 3.1 below.
All objects share the following requirements:
1. Authors MUST ensure they only have properties described in this specification. Properties not specified here MUST not be present. Authors MUST ensure that properties and structures marked as "Required" are present. Other properties MAY be omitted.
2. Authors MUST ensure objects do not have multiple properties with the same key.
Requirements for non-Required ("optional") properties only apply if the property is present.
List of groups of parameters that can be used together.
Authors MUST ensure that the `sets` object contains only `Set` objects. Authors MAY include a parameter in multiple `Set` objects. Authors are NOT REQUIRED to reference each parameter in at least one `Set` object.
A Consumer MAY encourage users to interact with parameters in a `Set` together (e.g. add, edit, or remove those parameters at once).
An object describing which parameter(s) specific Consumers SHOULD use for some purpose.
The `maps` property contains key–value pairs where the key identifies a given Consumer, and the value a `Map` object.
Consumers are NOT REQUIRED to have a corresponding `Map` object.
Consumers that look for a `Map` SHOULD publicly document their identifier key.
Authors MUST ensure that the `maps` object contains only `Map` objects. Authors MAY include a parameter in multiple `Map` objects. Authors are NOT REQUIRED to reference each parameter in at least one `Map` object.
How the template's wikitext representation SHOULD be laid out. Authors MAY choose to use this parameter to express that a template will be better understood by other human readers of the wikitext representation if a template is in one form or the other.
If the parameter is set to `'block'`, it MUST be interpreted as the format string `'{{_\n| _ = _\n}}'`. If the parameter is set to `'inline'` it MUST be interpreted as the format string `'{{_|_=_}}'`.
If the parameter is set to `null`, Consumers SHOULD create the same representation as for `'inline'` format for new template transclusions, and SHOULD attempt to use the same formatting for new parameters as for existing ones for existing transclusions that are edited.
In the absence of the parameter being set, the system will supply `null` as a fallback value.
* Default: Key of this `Param` object as referenced from `Root.params`.
Label of this parameter.
Authors are RECOMMENDED to provide unique labels for each parameter.
Consumers SHOULD use this when referring to a parameter in the interface for users.
#### 3.2.2 `description`
* Value: `null` or `InterfaceText`
Explanatory text describing the purpose of this parameter to a User.
Authors are RECOMMENDED to give each parameter a description. Authors MAY use include hints as to how to the format the parameter value.
For example, a template parameter called `name` might have as its description _"The name of the author of the book, to positively identify and attribute the claim. The name should be given as it would appear in the author's native language, script and culture."_.
Consumers SHOULD provide this description to a the User when selecting and altering parameter values.
#### 3.2.3 `required`
* Value: `boolean`
* Default: `false`
Whether the template being described requires this parameter to be present in order to function properly. For example, a template used to render a hyperlink to a book viewer might mark its "ISBN" parameter as required, whereas it might consider a parameter "publication date" to be optional.
Authors SHOULD only set this flag if the template will not function correctly without this parameter being set.
Consumers SHOULD encourage the User to fill in these parameters, and MAY prevent users from transcluding a template when a required parameter has not been set.
#### 3.2.4 `suggested`
* Value: `boolean`
* Default: `false`
Whether the parameter is recommended to be set to an explicit value for the template transclusion to be useful. This status is less strong an indicator than `required`. For example, in a book template the author's name might be `suggested`, whereas the title might be `required`.
Authors MUST NOT use `suggested` for parameters without which the template will not function correctly.
Consumers MAY encourage users to fill in a suggested parameter, but SHOULD NOT prevent users from transcluding a template when a suggested parameter is not set.
#### 3.2.5 `deprecated`
* Value: `boolean` or `string`
* Default: `false`
Whether this parameter is discouraged from usage. Seting to `false` indicates the parameter is not deprecated.
Authors are RECOMMENDED to, when marking a parameter as deprecated, provide a `string` of explanatory text describing why the parameter is deprecated (and what parameter or parameters the user should use instead). Alternatively, Authors MAY use the value `true` in absence of explanatory text.
Authors MUST NOT provide a `Param` object in `Root.params` for any alias. To describe a discouraged parameter with additional information, authors SHOULD describe the parameter as deprecated instead of alias.
Consumers SHOULD display aliases where entered as secondary to the primary name.
A dynamically-generated default value in wikitext, such as today's date or the editing user's name; this will often involve wikitext substitution, such as `{{subst:CURRENTYEAR}}`.
Consumers MUST insert a parameter's autovalue by default if this parameter is used in a transclusion, and SHOULD indicate this value to the user and give them the opportunity to change the value.
Each key in a `Map` object can be arbitrary. The value must match a parameter name, a list of parameter names, or list containing lists of parameter names.
The key corresponds to the name of a Consumer variable that relates to the specified parameter(s).
A format string describes how whitespace should be added to a template instantiation in wikitext. A format string looks like `{{_|_=_}}`, with optional whitespace and extended underscores. Formally, its structure is given by the following grammar:
To format a template invocation according to the format string, first split it in three parts, corresponding to `StartFormat`, `ParameterFormat`, and `EndFormat` in the grammar above. In the following, to "replace the `Hole`" with some value means to first pad a non-empty value with spaces on the right until it is at least as many characters long as the replaced underscore sequence. Zero-length values are not padded.
Begin with `StartFormat`, and replace the `Hole` with the name of the template to create the "output string". If `StartFormat` begins with a newline and template is already at the start of a line (the character preceding this template invocation is a newline or the template is at the start of the output), delete the initial newline from the output string.
For each parameter, if `ParameterFormat` begins with a newline and the last line in the output string is nothing but whitespace and comments, then delete the newline from the beginning of the `ParameterFormat`. Then append `ParameterFormat` to the output string after replacing the first `Hole` with the name of the parameter and the second `Hole` with the value of the parameter.
Finally, if `EndFormat` begins with a newline and the last line in the output string is nothing but whitespace and comments, then delete the newline from the beginning of the `EndFormat`. Or, if there were no parameters, also delete the newline from the beginning of the `EndFormat`. Append the `EndFormat` to the output string.