Extension talk:TemplateData
Add topicMultiple or fallback type values
[edit]I found type multiple type values like "string/wiki-page-name" and "string/line" in TemplateData added to English Wikipedia in 2013. I'm not seeing this feature documented at Help:TemplateData § Type parameter. How have consumers of TemplateData responded to these type values now and in the past? Is it a deprecated feature from the past or a planned for the future?
It makes some sense to me to include both a type indication and an expected or enforced indication of single-line vs. multi-line for many types like unbalanced-wikitext, content, and string. It could also make sense to provide fallback values when a type is not yet implemented or has been removed. Daask (talk) 16:09, 5 January 2025 (UTC)
- It appears this was just the primary name for the current type "wiki-page-name" back then. So this is partially just a request to incorporate this into the documentation.
- However, I'm not sure what the documentation should say. While "string/line" represents "line" as a subtype of "string", I'm still not sure how consumers treat a type value like "string/nonsense", then or now. Is there currently a fallback mechanism for types or is one planned?
- I guess this is also a feature request for single-line vs. multi-line indications for all three types of unbalanced-wikitext, content, and string. Daask (talk) 16:15, 5 January 2025 (UTC)
Why no spaces in "inline" format?
[edit]According to Help:TemplateData#Template data parameters, the "inline" format means:
When inserted, the template will lay its wikitext out on a single line with no white space between elements, like so:
{{Foo|bar=baz|longparameter=quux}}
This corresponds to TemplateData Specification, but such lack of separating spaces is considered editor-hostile and explicitly discouraged at least in English Wikipedia. So why was it chosen as a "standard"? — Mikhail Ryazanov (talk) 22:50, 23 January 2025 (UTC)
- @Mikhail Ryazanov: Different wikis have different standards over time. When we made the code a decade ago, this was the preferred standard at (amongst many others) the English Wikipedia. You link to an informal guidance page for bot authors that declares itself not to be policy, but it seems a reasonable clue that the English Wikipedia's view has changed since 2013.
- It is possible to change the code implementing the standard, but presents a big social problem. Changing the standard would have a massively disruptive effect, as millions of articles would randomly be changed in how they were formatted when people edit them. That said, if you can demonstrate widespread consensus across many wikis you could file a Phabricator task for it to be changed. Jdforrester (WMF) (talk) 22:15, 24 January 2025 (UTC)
- I think it’s the standard because it was chosen with very short templates in mind. Yes, cite templates are quite difficult to read without the spaces, but I think {{tlx|foo}} is actually more readable without spaces (and the extra spaces would also change its meaning due to how leading/trailing spaces in unnamed parameters are handled). And you always have the option to use a custom format if that improves readability, like for cite templates.
- Due to the very short templates case, I wouldn’t support changing the meaning of the
inlineformat, but I can support a new format likeinline-spaced(especially if the extension automatically translates this to a custom format string, so that consumers like VisualEditor, TemplateWizard, gadgets, user scripts, Toolforge tools etc. don’t need to be updated). —Tacsipacsi (talk) 23:32, 24 January 2025 (UTC)- Yes, I understand that changing the meaning of
"inline"now would be problematic and that at least some short templates are actually more readable without spaces (although the leading/trailing spaces are a problem only for poorly designed templates because the guidelines that I've seen strongly suggest using {{trim}} for unnamed parameters). So adding another pre-defined formal like"inline-spaced"(or some other name) would be nice. Let me ping @Headbomb who wrote the enwiki guidelines. — Mikhail Ryazanov (talk)- "Guideline" is a strong word here, en:WP:EDITORHOSTILE contrasts a badly-structured long template vs a well-structured long template. I personally prefer that exact structure (
|para=value), but others will prefer| para = valueor other variants, but that's really only for citation templates. Other templates, especially short ones like en:template:val don't have a need for spaces. Headbomb (talk) 02:53, 25 January 2025 (UTC)- We all agree that current
"inline"is appropriate for "short" templates. The question is whether there are sufficiently many "long" templates that need spaces, and thus defining a "standard" format for them would be useful for convenience and consistency. Or you think that each of them should just use a manual override"format": "{{_ |_=_}}"(as at least some of them currently do)? Is there a simple way to find templates with "too many" named parameters (but not using the"block"or block-like format) to get some statistics? — Mikhail Ryazanov (talk) 06:17, 25 January 2025 (UTC)(although the leading/trailing spaces are a problem only for poorly designed templates because the guidelines that I've seen strongly suggest using {{trim}} for unnamed parameters)
- If the leading/trailing spaces cause problems, then indeed, the template is poorly designed. However, there may be templates where both inputs have a meaning, but they’re different – those are not poorly designed, but take advantage of the MediaWiki template syntax.
Is there a simple way to find templates with "too many" named parameters (but not using the
"block"or block-like format) to get some statistics?- The API can return complete TemplateData for all templates that have it on a given wiki (with several requests if there are many well-documented templates); with this data, it’s only the question of a program that processes it and criteria to tell what “too many” is. (How many parameters? How to handle optional ones – there may be templates that have loads of optional parameters, while usually only a handful are used at the same time? Does it matter if the parameters are named or numbered? Or how long the parameter names are? Do considerably longer or shorter aliases count?) —Tacsipacsi (talk) 21:10, 25 January 2025 (UTC)
But such templates should not use any automatic reformatting at all (until there is a mechanism to declare which parameters are whitespace-significant).there may be templates where both inputs have a meaning, but they’re different – those are not poorly designed, but take advantage of the MediaWiki template syntax
- Thanks for the API suggestion! For enwiki, "several requests" was actually >100 with the maximal limit of 500 per request... See some analysis below. — Mikhail Ryazanov (talk) 06:23, 28 January 2025 (UTC)
- We all agree that current
- "Guideline" is a strong word here, en:WP:EDITORHOSTILE contrasts a badly-structured long template vs a well-structured long template. I personally prefer that exact structure (
- Yes, I understand that changing the meaning of
The only way this could be implemented and be sustainably templatified or some such would be to have something like output:"\n |para=value" to have the output of a template display like
{{cite journal
|last=value
|first=value
|year=value
|title=value
...
}}
and something like output:" |para = value" to have the output of a template like
{{cite journal |last = value |first = value |year = value |title = value ...}}
But quite honestly, I don't see the demand for this. Headbomb (talk) 20:20, 26 January 2025 (UTC)
- As I wrote above,
you always have the option to use a custom format if that improves readability, like for cite templates.
The syntax is described in Help:TemplateData#Custom formats. The question is whether it makes sense to define another standard format – standard formats have the advantages that they are, well, standard, so different templates won’t look different; and that they have buttons in the TemplateData editor and meaningful descriptions in the rendered documentation, both of these latter making them much easier to handle for non-techy people. —Tacsipacsi (talk) 23:20, 26 January 2025 (UTC)- To be specific, here are the statistics that I've collected for English and Russian Wikipedias (the two where I'm active):
Templates by format (English Wikipedia) formatTotal 5–9 >9 ⟨pos.⟩ ⟨named⟩ Comment block820 59 593 0.5 40.7 Block-like
("aligned" means formats with___…)(aligned) 213 1 204 0.1 82.4 {{ _\n | _ = _\n }}1 0 1 0.0 30.0 {{_\n|_ = _\n}}1 0 1 0.0 33.0 {{_\n|_=_\n}}3 0 3 0.0 29.0 {{_ |_=_\n}}2 0 2 0.0 64.0 {{_\n|_=_ }}2 0 2 0.0 41.0 {{_\n| _ = _\n}}12 0 7 0.0 152.9 Must be block{{_\n| _ = _\n}}\n7 0 5 0.1 23.7 Must be block?{{_\n | _ = _\n}}2 0 2 0.0 68.0 Wrong {{_\n| __ = _\n}}\n1 0 1 0.0 31.0 User's test template {{_|\n_=_\n}}1 0 0 1.0 0.0 Template:Hatnote groupnull51341 467 962 0.1 2.5 ~1400 candidates with ≥5 parameters inline2049 312 253 1.3 5.6 ≳500 candidates with ≥5 parameters {{_|_=_}}6 0 4 0.0 16.5 Must be inline{{_|_ = _}}\n17 2 0 0.8 1.6 Bad idea {{_ |_=_}}89 5 84 0.0 76.0 "Editor-friendly" inline {{_|_=_}}\n25 2 0 0.7 1.4 Subtemplates? {{_| _ = _}}\n1 0 0 2.0 1.0 \n{{ _ | _=_ }}5 0 2 3.8 6.6 \n{{_ | _ = _}}2 0 2 2.0 10.0 \n{{_|_=_}}2 2 0 0.0 8.0 \n{{_|_=_}}\n2 2 0 0.0 5.0
Templates by format (Russian Wikipedia) formatTotal 5–9 >9 ⟨pos.⟩ ⟨named⟩ Comment block443 30 390 0.2 31.9 Block-like
("aligned" means formats with___…)(aligned) 64 0 64 0.0 36.0 inline2080 33 20 0.3 1.1 Some are "editor-hostile" null2681 46 58 0.8 1.9 ~100 candidates with ≥5 parameters {{_ |_=_}}23 1 22 0.0 65.7 "Editor-friendly" inline {{_ |_=_ }}1 0 1 0.0 54.0 Same as above except extra final space \n{{_|_=_}}\n7 0 0 6.4 0.4 Subtemplates for tables {{_|\n_ = _}}1 0 0 0.0 4.0 Subtemplate for infobox
- As can be seen, the "editor-friendly inline" custom format
{{_ |_=_}}is currently used in 98 enwiki templates and in 23 + 1 ruwiki templates. The{{_ |_ = _}}mentioned by Headbomb and its variant{{_ | _ = _}}are actually not used in TemplateData for inline templates. At the same time, there are hundreds of "long" templates (with ≥10 parameters) that have"format": "null"or"inline"but potentially should use spaces (some in Russian Wikipedia definitely must, which brought me here). - So while the number of templates using
{{_ |_=_}}is an order of magnitude smaller than those usingblock, there are still many of them (and, I suspect, they are used much more often, so consistency does matter). Thus, I think, it will be justified to make this format another standard option (inline-spaced, as proposed, or perhaps justspaced). - Another remark: since there are also many "aligned" block formats with manually defined length, it might be useful to create something like
block-alignedthat will calculate the necessary length automatically. Not as a universal solution (some templates have very few very long parameter names, alignment of which is better to be neglected), but as a convenience for relatively simple cases. — Mikhail Ryazanov (talk) 06:23, 28 January 2025 (UTC) - Some additional statistics (abbreviated) for other languages:
- As can be seen, the "editor-friendly inline" custom format
Templates by format (German Wikipedia) formatTotal 5–9 >9 ⟨pos.⟩ ⟨named⟩ Comment block669 75 458 1.6 19.1 Block-like (aligned) 372 15 354 0.0 30.2 other \n{{_\n...\n}}\n51 17 23 — — null719 78 71 1.5 4.9 inline4403 247 26 2.3 2.2 {{_ |_=_}}350 125 32 0.5 6.3 "Editor-friendly" inline {{_ | _=_}}3 2 0 0.0 5.7 Same with space after |{{_| _=_}}1 0 0 0.0 3.0 Vorlage:TheBook\n{{_|_=_}}\n1570 0 1 0.1 0.1 1 with ≥10 parameters, rest with ≲1 {{_|_=_}}\n1 0 0 2.0 1.0 \n{{_ |_=_}}\n2 1 0 6.5 4.5
Templates by format (French Wikipedia) formatTotal 5–9 >9 ⟨pos.⟩ ⟨named⟩ Comment block191 31 126 0.3 22.5 Block-like (aligned) 590 27 377 0.1 37.5 other {{_\n...\n}}10 1 8 — — null6988 147 219 1.2 1.9 inline1654 68 55 1.4 1.7 {{_ |_=_}}6 0 6 0.0 77.0 "Editor-friendly" inline {{_ |_= _}}2 1 1 1.5 9.0 Modèle:HlistModèle:Composition Division de Francemust be block-like{{_|_= _}}\n1 0 0 0.0 3.0 Modèle:Promotionnel{{_|_=_}}57 2 0 0.3 0.5 Must be inline{{_|_=_}}\n55 4 2 3.4 5.2 \n{{_|_=_}}1 0 0 0.0 0.0 \n{{_|_=_}}\n50 4 3 4.1 2.5
Templates by format (Spanish Wikipedia) formatTotal 5–9 >9 ⟨pos.⟩ ⟨named⟩ Comment block103 8 80 0.7 74.8 Block-like (aligned) 5 0 5 0.0 53.8 {{_\n| _ = _\n}}1 0 1 0.0 14.0 Wrong null286 23 77 1.7 14.0 inline326 14 15 1.4 4.5
- So, Spanish Wikipedia apparently doesn't care about custom formats at all (and not much about TemplateData), French has only 6 templates with
{{_ |_=_}}, but German has 350 (+3) of them — almost as many as "aligned" and more than a half ofblock. German and French also have hundreds ofnullandinlinewith many parameters, so some of them might be candidates for "editor-friendly inline". - BTW, French uses "aligned" a lot. Might be the best candidate for testing automatic length calculation. — Mikhail Ryazanov (talk) 02:35, 29 January 2025 (UTC)
- So, Spanish Wikipedia apparently doesn't care about custom formats at all (and not much about TemplateData), French has only 6 templates with
Boolean
[edit]Hello all - has there been any proposals to allow "true" and "false" or "yes" and "no" as well as "1" and "0" for boolean values? I'm looking to introduce boolean values on my wiki but having 1 and 0 in the source code isn't the most useful for people who are not familiar with boolean and is also confusing when we are already dealing with various numerical values. Garuda3 (talk) 12:17, 20 June 2025 (UTC)
Bug fix request: “Parameter names cannot be empty”
[edit]If I try to document the empty-name parameter {{{}}} I get the message
- Parameter names cannot be empty. To document unnamed parameters use their internal numbers "1", "2", and so on.
Yet, template names can be empty. Should the above error message be removed? --Grufo (talk) 16:22, 18 September 2025 (UTC)
- @Grufo: I do not understand. Wikitext template parameter names cannot be empty, but maybe I am not understanding you. Can you give an example of a template using this that you want to document? Jdforrester (WMF) (talk) 17:29, 18 September 2025 (UTC)
- Hi Jdforrester. They can be empty though. If you create a template containing,
* The parameter <code>| 1 =</code> is “{{{1}}}” * The parameter <code>| 2 =</code> is “{{{2}}}” * The parameter <code>| =</code> is “{{{}}}”
- and you transclude it with,
{{My test template | 1 = Foo | 2 = Bar | = Hello world! }}
- you get:
- The parameter
| 1 =is “Foo” - The parameter
| 2 =is “Bar” - The parameter
| =is “Hello world!”
- The parameter
- As for the example, I wanted to document {{en:Plural}}, and explain that when transcluding that template the
| =parameter should never be set, because it is used internally and is expected to be always unset. Another realistic example in which the empty-name parameter{{{}}}can be used is in a template that mimics the {{#switch:}} parser function, in which it simply means to check for an empty string. --Grufo (talk) 21:02, 18 September 2025 (UTC)- @Grufo: This feels like you have found a bug in the MediaWiki legacy parser. You should not expect
{{{}}}to do anything consistently, and you should certainly not use it in a template used on any page. I'll file a task. Jdforrester (WMF) (talk) 12:27, 19 September 2025 (UTC)- @Jdforrester: Many templates rely on the empty-name parameter for doing multilevel substitution via
{{{|safesubst:}}}. So removing support for the empty-name parameter will create a lot of trouble. Also it will make it impossible to emulate the switch statement. Based on what should the empty-name parameter not exist according to you? --Grufo (talk) 12:43, 19 September 2025 (UTC)- @Grufo FYI, the Phabricator task that got opened is phab:T405104 (in case you wish to comment in it). Best, —a smart kitten[meow] 18:16, 19 September 2025 (UTC)
- @Jdforrester: That's great, thank you. --Grufo (talk) 19:38, 19 September 2025 (UTC)
- @Jdforrester: Not sure how the Phabricator task works. How long will it stay open? Should the empty-name parameter remain forbidden/undocumentable via TemplateData even if it is currently usable? --Grufo (talk) 14:18, 2 October 2025 (UTC)
- @Grufo: It's likely to be open to discussion for months or even years, sorry for not making this specific. Jdforrester (WMF) (talk) 15:33, 2 October 2025 (UTC)
- @Jdforrester: Not sure how the Phabricator task works. How long will it stay open? Should the empty-name parameter remain forbidden/undocumentable via TemplateData even if it is currently usable? --Grufo (talk) 14:18, 2 October 2025 (UTC)
- @Jdforrester: That's great, thank you. --Grufo (talk) 19:38, 19 September 2025 (UTC)
- @Grufo FYI, the Phabricator task that got opened is phab:T405104 (in case you wish to comment in it). Best, —a smart kitten[meow] 18:16, 19 September 2025 (UTC)
- @Jdforrester: Many templates rely on the empty-name parameter for doing multilevel substitution via
- @Grufo: This feels like you have found a bug in the MediaWiki legacy parser. You should not expect
- As for the example, I wanted to document {{en:Plural}}, and explain that when transcluding that template the
Debugging The "Cite web" template doesn't yet have a description, but there might be some information on the template's page.
[edit]Continuing from this topic on Wikipedia We are having a problem with the Visual Editor recognizing TemplateData from imported Wikipedia templates.
The wiki is running MediaWiki 1.43.6, and our extensions are current and up-to-date.
As an example, we imported Wikipedia's Template:Cite web (and underlying templates/modules) as our own Template:Cite web
We recently refreshed the template and documentation subpage for Template:Cite web on the wiki and now when using the Visual Editor and trying to cite a website we get "The "Cite web" template doesn't yet have a description, but there might be some information on the template's page."
Following the link the TemplateData section looks correct. Editing the Template:Cite web/doc (section) shows the Edit template data button followed by the link for Information about template data which seems to confirm the TemplateData is correctly being recognized.
Are there any further debugging techniques that might help me get to the bottom of why the Visual Editor doesn't see the TemplateData and thinks the template doesn't yet have a description.? Peculiar Investor (talk) 22:08, 10 February 2026 (UTC)
- TemplateData sometimes caches data too aggressively. Have you edited (potentially null-edited) the template since the import of the documentation subpage? (With page histories locked down, I cannot check it myself…) —Tacsipacsi (talk) 11:48, 14 February 2026 (UTC)
- Thank you. I had tried purging the template page and that had not solved the issue. However doing the suggested null-edit has fixed the problem. Much appreciated. Peculiar Investor (talk) 14:02, 14 February 2026 (UTC)