Jump to content

Wikipedia:TemplateData

From Wikipedia

Template:Testcases other


Wetin be TemplateData?

[edit source]

TemplateData na standard way to describe one template. Default VisualEditor, optional 2017 wikitext editor, plus oda tools dey use am make editing template easy for user. Both VisualEditor and 2017 wikitext editor get one wizard wey help edit templates, but make the wizard really useful, e need show user correct information about each template, like short explanation of wetin the template dey do plus the parameters inside am. Any wiki editor fit write this information using TemplateData.

Editing without TemplateData

[edit source]

If TemplateData no dey, system go automatically generate list of supported parameters.

E no go explain wetin value each parameter suppose get.

Editing with TemplateData

[edit source]

If TemplateData dey, when you insert template inside article or edit existing template transclusion, e go show list of supported parameters plus description for each one.

TemplateData dey give better explanation for every parameter, so e make am easier for users to edit template transclusions inside articles.

How to add TemplateData

[edit source]

Anybody fit help by adding TemplateData to templates (especially popular ones like infoboxes) so editing them for VisualEditor go easy. The best way na to open the TemplateData editor by clicking the button wey dey top of the edit page: Edit template data

You fit also write TemplateData by hand. This one be simple example wey you fit put for template documentation page as new section before the "See also" section if e dey.

==TemplateData==
{{TemplateData header}}

<templatedata>{
  "description": "put description here",
  "params": {
    "first parameter": {
      "label": "x",
      "description": "x",
      "type": "string",
      "suggested": true,
      "autovalue": "automatic value wey system derive",
      "default": "default value",
      "required": false
    }
  }
}</templatedata>

The TemplateData tutorial explain well-well how to add TemplateData manually to one template.

Adding suggested values for parameters

[edit source]

The parameter property suggestedvalues let you define list of values wey VisualEditor users go see inside dropdown menu make dem choose easily. You fit do am directly inside JSON or by using the TemplateData editor without writing code. Both methods dey explained below.

After you add the values into TemplateData, VisualEditor go show dem inside combo box (dropdown wey users still fit type custom value inside). User fit click the value wey e want. If the list long—for example, list of regions or states for one country—the user fit start typing and the list go filter itself show only matching values. To change value, user just clear the field and the full dropdown list go show again. If user need value wey no dey the list (for example, "message in a bottle"), e fit type am manually.

Make suggested values show inside VisualEditor, the parameter type must be one of these:

  • content
  • line
  • string
  • number
  • unknown
  • unbalanced wikitext

Other parameter types (file, page, template, user, date, boolean, URL) no support this feature for now because VisualEditor already get special functions for them (like autocomplete), and e fit clash with the suggested values dropdown.

Adding suggested values in wikitext

[edit source]

To add suggested values, add new property "suggestedvalues" to the parameter for JSON. The value for "suggestedvalues" must be list of strings.

Example:

"media_type": {
	"label": "Media type",
	"example": "Newspaper",
	"type": "string",
	"description": "Which medium publish the article?",
	"suggestedvalues": [
    	"Journal",
    	"Book",
    	"Newspaper",
    	"Magazine"
	]
}

Adding suggested values with the TemplateData editor

[edit source]

For the parameter types wey dey listed above, you fit use the TemplateData editor add suggested values.

  • Step 1. Click "Manage TemplateData".
  • Step 2. Click the parameter name wey you want add suggested values to.
  • Step 3. If e never be so already, change the parameter type to one of these: content, line, string, number, unknown, or unbalanced wikitext. New input field wey dem call "Suggested values" go appear. If the parameter already get one of these types, the field already go dey show.
  • Step 4. Type the suggested value or values, including spaces and special characters if dem dey, then press Enter make e add am to the list.

Here you fit see example of how to add suggested values with the TemplateData editor.

Importing TemplateData

[edit source]

Some templates dey import their TemplateData from WP:Wikimedia Commons. You fit do this one by using Template:Ml. For example, Template:((#invoke:TNT|doc|Uses TemplateStylesTemplate:)) load TemplateData from c:Data:Templatedata/Uses_TemplateStyles.tab, wey Template:Uses TemplateStyles/doc dey use.

Templates wey dey use am

[edit source]

See also

[edit source]