Wikipedia:VisualEditor/TemplateData
This Wikipedia page needs to be updated. Please help update this Wikipedia page to reflect recent events or newly available information. |
- Main page
- Feedback at MediaWiki or local feedback
- Sandbox (no account required)
- Why are the developers building this?
- Documentation:
- Development:
- Customization
- Known problems
- Requests for Comments (RfCs): Jul 2013 a, Jul 2013 b, Jul 2015, Sep 2015
What is template data?
mali niŋTemplate data is the standardized description of a template, used by the default VisualEditor, the optional 2017 wikitext editor and other tools to improve the template-editing experience for the user. Both VisualEditor and the 2017 wikitext editor include a wizard to edit templates, but for the wizard to be most useful, it needs to present specific information to the user about each template, such as a short description of the template's purpose and its parameters. This information is codified formally (by any wiki editor) using template data.
Editing without template data
mali niŋWithout template data, each parameter needs to be added manually when inserting a new template.
No information is provided about what the value of the parameter should be.
Editing with template data
mali niŋWith template data, a list of supported parameters (and their description) is provided for the template.
Template data provides context for each parameter, and makes it much easier for users to modify templates.
Adding template data
mali niŋAnyone can help by adding template data to templates (particularly high-profile ones, such as infoboxes) so that they are easier to edit in VisualEditor. The following is a minimal example, placed on a template's documentation page:
<templatedata>{
"description": "insert description here",
"params": {
"first parameter": {
"label": "x",
"description": "x",
"type": "string",
"suggested": true,
"autovalue": "derived automatic value",
"default": "default value",
"required": false
}
}
}</templatedata>
You can also add or edit template data using a GUI, by pressing the following button which appears at the top of the edit page:
The template data tutorial explains in detail how to add template data information to a template.
Adding suggested values for parameters
mali niŋThe parameter property suggestedvalues
lets you define a list of parameter values to be shown to VisualEditor users in a dropdown for easy selection. This can be done either directly in JSON or using the TemplateData editor with no coding required. Both methods are explained in detail below.
Once the values have been added to template data, the VisualEditor will display them in a combo box (a dropdown into which users can also enter a custom value). The user selects the desired value by clicking on it. If the list of values is long - for example, a list of a country’s states - the user can begin typing in the field, whereupon the list will be filtered to show only values containing the typed text. To change an entered value, the user must simply clear the field, and the full dropdown list will appear again. If the user needs a value not included in the list (for example, "message in a bottle") they can type it in manually.
For suggested values to be displayed in the VisualEditor, the parameter’s type must be set to one of the following options:
- content
- line
- string
- number
- unknown
- unbalanced wikitext.
Other types (file, page, template, user, date, boolean, URL) are not currently supported because they have special functionalities in the VisualEditor already (such as autocomplete) which would interfere with the dropdown menu for suggested values in the VisualEditor.
Adding suggested values for parameters in wikitext
mali niŋTo add suggested values to any parameter type, add the new property “suggestedvalues
” to the parameter in JSON. The “suggestedvalues” attribute must be a list of strings.
An example might look like this:
"media_type": {
"label": "Type of media",
"example": "Newspaper",
"type": "string",
"description": "In what medium was the article published?",
"suggestedvalues": [
"Journal",
"Book",
"Newspaper",
"Magazine"
]
}
Adding suggested values for parameters with the template data editor
mali niŋFor the parameter types listed above, you can add suggested values using the template data editor.
Step 1. Click on "Manage TemplateData".
Step 2. Click on the name of the parameter you want to add suggested values to.
Step 3. If it’s not already, set the type of the parameter to one of the following: content, line, string, number, unknown or unbalanced wikitext. A new input field "Suggested values" will appear. If the parameter is already set to one of these types, the input field should already be visible.
Step 4. Type in the suggested value(s), including any spaces and special characters, and press enter to add it to the list.
Here you can see an example of how to add suggested values in the TemplateData editor.
Used templates
mali niŋSee also
mali niŋ- Wikipedia:VisualEditor/TemplateData/List A list of all pages with template data