Commons:TemplateData
<templatedata>JSON</templatedata> ./. {{TemplateBox}}
TemplateData
TemplateData is a way to store information about template parameters (the description of those and of the whole template) for both humans and machines. It is used by VisualEditor and possibly other tools like Upload Wizard.
Existing template documentation
At Wikimedia Commons, it is recommended to use {{TemplateBox}} with either ‎useTemplateData=1 or ‎useTemplateData=only on the ‎/doc subpage and transcluding it with {{Documentation}} into the template.
‎<nowiki>
-tags can be wrapped around the arguments, if required, to avoid templates being expanded.
Newly created template documentation and imports
Another option, especially for imported templates, or for users with JSON experience, is placing raw
‎<templatedata>
-tags into the Wikitext of the template, as described in various Wikipediae.
Discussion
There is an ongoing discussion about that matter. Feel invited to comment if you are experienced in either way, your time permits and if you like to share your opinion or to make a suggestion.
Wikipedia's help about TemplateDataCommons-specific information
Using TemplateBox
Every entity, except inherit that is documented at the TemplateData technical documentation, is supported by {{TemplateBox}}. Conversion to JSON is done by a LUA module. The LUA module automatically converts traditionally used parameters as well as the new ones to both, TemplateData, as well as the "historic table", on demand. The "historic table" is the table which was used to show parameter information at Wikimedia Commons before TemplateData was invented.
Required parameters
|desc= (or in its translated form), parameters and their description
Translation
Naming
Both, old names and new names are supported but treated differently if both of them are supplied.
For example, while creating the "historic table", if both 1def and 1default where supplied, the value for 1def would be used. For generating TemplateData, the preference is the other way around.
Overriding
It's possible to override a specific entity, either for the "historic table" or for TemplateData.
Pay attention
Activation
TemplateData can be activated setting the useTemplateData parameter to 1 or to only. The former will add a collapsed version of the table; the latter one replaces the "historic table" with the TemplateData table. In both cases, TemplateData is available through the API.
Fetching TemplateData (e.g. for TemplateBox itself)
/w/api.php?action=templatedata&format=json&titles=Template%3ATemplateBox (raw result, pretty result)
Advantages
Issues
Grouping sets is currently not supported in the "historic table". Set labels are not supported to be multilingual (ideas how one could achieve this are truly welcome).
Example
{{TemplateBox | useTemplateData = 1 | 1 = artist | 1aliases = Artist | 1label-en = Artist | 1type = string <!-- used as the parameter description in the main parameter area of the documentation --> <!-- and in the template data section unless overridden with 1d-td-langcode --> | 1d-de = Künstler, der das ursprüngliche Kunstwerk geschaffen hat.<br/>Benutze möglichst immer {{Creator:Vorname Nachname}} mit der Vorlage {{Tl|Creator}}. | 1d-en = Artist who created the original artwork.<br/>Use {{Creator:Name Surname}} with {{Tl|Creator}} template whenever possible. | 1d-fr = Artiste ou artisan à l'origine de l'œuvre.<br/>Dans la mesure du possible, utiliser le modèle {{Tl|Creator}}. | 1d-sv = Artist som skapade originalverket.<br/>Använd {{Creator:Förnamn Efternamn}} med {{Tl|Creator}}-mallen om detta är möjligt. <!-- this overrides 1d-en in the Template data section --> <!-- and all other translations unless each is provided as desc-td-langcode --> | 1d-td-en = Artist who created the original artwork; this overrides "1d-en" in the Template data section; "1d-en" is used in the template "Parameter" section. | 1def-de = Freifeld, angezeigt als: "{{int:wm-license-information-author}}". | 1def-en = blank field presented as: "{{int:wm-license-information-author}}". | 1def-fr = champ vide: « {{int:wm-license-information-author}} » | 1def-sv = tomt fält, visas som: "{{int:wm-license-information-author}}" <!-- used as the description of the template in the main documentation area --> <!-- and in the Template data section unless overridden with desc-td-langcode --> | desc-de = Deutsche Übersetzung der {{tl|Vorlagen}}beschreibung | desc-en = English translation of the {{tl|template}} description <!-- this overrides desc-en in the Template data section --> <!-- and all other translations unless each is provided as desc-td-langcode --> | desc-td-en = English translation that is used in the Template data section instead of "desc-en". This will also replace all desc-langcode translations, unless corresponding "desc-td-langcode" is provided. }}
A live example is Template:Information/doc (edit that enabled TemplateData through TemplateBox, API-result showing the JSON generated by the Lua Module behind TemplateBox)
Experimenting
You can use Special:ExpandTemplates to experiment with how the template will output the template documentation and the Template data section; e.g., copy the example above and paste it into the input text on the Special:ExpandTemplates page; then click on the ok button to see the result.
Last edited on 14 August 2021, at 09:41
Files are available under licenses specified on their description page. All structured data from the file and property namespaces is available under the Creative Commons CC0 License; all unstructured text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and the Privacy Policy.
Privacy policy
Terms of Use
Desktop
HomeRandomNearbyLog inSettingsDonateAbout Wikimedia CommonsDisclaimers
WatchEdit