Help talk:TemplateData

Jump to navigation Jump to search

About this board

Previous discussion was archived at Help talk:TemplateData/Archive 1 on 2015-09-04.

Vexations (talkcontribs)

I've tried to add TemplateData to a template in my user space, but couldn't get it to work. To make sure the problem wasn't with my template, I copied an existing one that worked on enwp {{0}}, and found that it stopped working when I tried to place the TemplateData in User:username/templates/template/doc. Does TemplateData only work in the Template namespace? Thanks, ~~~~

ExE Boss (talkcontribs)

Note that you also need to transclude the documentation subpage into the User template page for it to work, e.g.: {{m:User:ExE Boss/OtherProjects}}.

Vexations (talkcontribs)

Thanks, yes, that's a good point, but I think I had that right: immediately at the end the last line of the template, I called had the documentation template embedded in a noinclude tag. The working template that I copied also did that, but stopped working in user space.

ExE Boss (talkcontribs)

Right, I forgot to mention, that you also need to perform a null edit/hard purge of the User template page, in order to properly update the templatedata page property (the TemplateData  extension does this automatically in the Template namespace when editing the doc[1] subpage).

References

Jonesey95 (talkcontribs)

It is always helpful to link to an example page when you are asking for technical help.

Vexations (talkcontribs)

Thanks for helping everyone! It's fairly easy to reproduce: Copy the 0 template (I just chose that because its one of the first in the list of templates that use TemplateData) and its doc subpage to your userspace. Now try to edit your sandbox with the Visual Editor and add the 0 template. My version that demonstrates the problem is at en:User:Vexations/templates/PB

Tacsipacsi (talkcontribs)

It doesn’t work in VisualEditor indeed, but it seems to be a bug in VE, not TemplateData: when I open your user subpage’s talk page in VisualEditor and try to insert the user subpage, no TemplateData is provided (and not even the title is visible in the autocomplete for the template name), while if I use the wikitext editor’s template inserter , it works perfectly.

Reply to "TemplateData in user space?"

Help with finding TemplateData's with errors

1
Shushugah (talkcontribs)

I recently fixed TemplateData on en:Template:Infobox organization but did not find an easy way to search for other potentially affected templates with errors, particularly high trafficl ones. Is there a tracking category for this? Shushugah (talk) 19:09, 13 September 2021 (UTC)

Reply to "Help with finding TemplateData's with errors"

Visual Editor corrupts TemplateData-generated transclusions on save, when not using short URL format

4
Summary last edited by Clump 21:59, 2 July 2021 2 months ago

As tracked in the referenced Phabricator bug, the Visual Editor does not support "long" URLs of the form https://site.name/index.php?title=Page_name. Only so-called "short" URLs, e.g. https://site.name/wiki/Page_name, are compatible with Visual Editor.

Bjsdaiyu (talkcontribs)

MW 1.35.0, TemplateData 0.1.2

I have templates defined using TemplateData. Filling in and editing these templtates works fine in Visual Editor (VE) up through the first save, for example this image, but upon subsequent edits it cannot find the template as shown here: it strangely believes that :index.php?title=Template:<Template Name> is the name of the Template page! Any thoughts

FeRDNYC (talkcontribs)

Hmm. A few questions:

  1. What does the "Generated from:" text show in the popup box for the template, when you commit the data edits in the Visual Editor (before you save)?
  2. What does it show after you save, then edit the page again?
  3. If you switch to Source Editing while you're re-editing the page, does it show the correct template transclusion, e.g. {{Cite book|something=|something_else=|...}}
  4. What is the URL format for your wiki? Like, what's the actual URL to Template:Cite book? What's the URL for the article you're editing?

On Wikipedia, Template:Cite book lives at https://en.wikipedia.org/wiki/Template:Cite_book.

So if I'm editing https://en.wikipedia.org/wiki/The_Cat_in_the_Hat and want to cite Dr. Seuss, the URL to Template:Cite Book has the same https://en.wikipedia.org/wiki/ prefix. Same for the article's edit interface, which loads from https://en.wikipedia.org/wiki/The_Cat_in_the_Hat?action=edit

But it looks like either your wiki is using old-style index.php?title= URLs and the Visual Editor is mishandling those, or something is configured to think the URLs should be index.php?title=-style when they're not. (Are there any rewriting rules / HTTP redirects configured on the wiki's web server, for article paths?)

GeoffreyHfr (talkcontribs)

I have the same problem. I just found a bug logged pointing at the no-usage of Short URL :

https://phabricator.wikimedia.org/T270219


They give some workaround.

I have just added $wgUsePathInfo=true; to my LocalSettings.php for it to work.

FeRDNYC (talkcontribs)

Ooh, good find @GeoffreyHfr, that bug clearly describes exactly the problem here. According to the info there, Visual Editor simply doesn't support index.php?title= URLs, period. Apparently it never has, since Wikipedia has used short URLs since long before Visual Editor became a thing.

(Might be nice if that was documented somewhere prominent, or if it had some way to detect those URLs and at least display a helpful error message. Still, at least now people have this bug to refer to, so that's something.)

Reply to "Visual Editor corrupts TemplateData-generated transclusions on save, when not using short URL format"

Custom format - two parameters on one row

2
Summary by Whatamidoing (WMF)
Kozuch (talkcontribs)

I want to format the template but use two parameters on one row like this:

{{TemplateName
 | param1 | param2
 | param3 | param4
}}

This is because I have a gallery - first param is name, second description for the same item, so should be on same row to make it nice.

{{Gallery
 | name1 | description1
 | name2 | description2
}}

Formating syntax tried (two pipes) but gave error:
{{_\n| _ = _ | _ = _\n}}
{{_\n| _ | _\n}}

I use nameless params - {{{1}}} {{{2}}} etc.

Tried syntax with multiple pipes but that gave errors. Is there a way to do this?

Whatamidoing (WMF) (talkcontribs)

Unfortunately, this can't be done right now. phab:T275457 is the ticket for the feature request.

קיפודנחש (talkcontribs)

so, wiki template syntax supports something called #switch.

the switch can have a "default", or not. when a parameter is _only_ used in a switch, and there is no "default", it means that only one of the suggested values will have any effect, and everything else is equivalent to no value at all.

the TD syntax should allow distinguishing between those two types of use. currently, the help page says

"If the user needs a value not included in the list (for example, "message in a bottle") they can type it in manually."

this makes sense for some parameters, and no sense for others (i.e., params only used in #switch with no default).

note that the TD is used by things other than the visual editor, for which this feature was requested for the longest time - see, e.g., phab:T224342.

peace

Tacsipacsi (talkcontribs)
Reply to "suggestedvalues"

Documenting Lua modules

4
Summary by 197.218.87.157
Adamw (talkcontribs)

Will TemplateData be used to document Lua? Can VisualEditor use TemplateData to give hints for module invocation?

Whatamidoing (WMF) (talkcontribs)

Are you meant to be invoking a module directly?

Adamw (talkcontribs)

Good point, thanks! There's already a /doc subpage (e.g. [1]) for the module itself, and that's all we need.

It's the functions within a module which can be invoked from wikitext, these take parameters, and this is where we would need the structured documentation. I'm not sure how we could provide these docs (or maybe editors feel this is not lacking?). LDoc and maybe other syntaxes would be appropriate for inlining docs in the source code, but wouldn't cover our use case. We pass an opaque frame and it's the args arguments within that define the module's MediaWiki interface. We also need a way to indicate which functions are meant to be public.

Needless to say, however we (if we) decide on a syntax, it should be machine-parsable so it can be leveraged by VisualEditor and other tools.

Reply to "Documenting Lua modules"

modifying fieldnames or labels in TemplateData edit

3
Snoreau88 (talkcontribs)

I wish to change the fieldnames or labels in an infobox. For example. When using the Template:Infobox country, I would like to change "Anthem" to "Devise". So in the article's infobox it would be :

Devise O Canada

and not

Anthem Ô Canada

Is this possible? Would the TemplateData editor be useful? I've played around with it without success.

Jonesey95 (talkcontribs)

You should ask this question on the template's talk page.

Snoreau88 (talkcontribs)

Ok, I finally figured a way to import the French language template Modèle: infobox pays into my personal wiki. And it is working.

Reply to "modifying fieldnames or labels in TemplateData edit"
BoldLuis (talkcontribs)

All TemplateData would include a link to Wikidata.

Whatamidoing (WMF) (talkcontribs)

Why?

185.127.147.131 (talkcontribs)

Because can be used in other projects.

BoldLuis (talkcontribs)

Without retyping all the data, fields an information.

Whatamidoing (WMF) (talkcontribs)

I don't think I understand your suggestion. This is the TemplateData for the English Wikipedia's "citation needed" template:

<templatedata>
 {
 "description": "The template is used to identify claims in articles, particularly if questionable, that need a citation to a reliable source.",
 "params": {
 "date": {
 "label": "Month and year",
 "description": "Provides the month and year of the citation request; e.g., 'January 2013', but not 'jan13'",
 "type": "string",
 "autovalue": "{{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}",
 "suggested": true
 },
 "reason": {
 "label": "Reason for citation",
 "description": "A reason as to why, or for what content, the citation is needed; use single quotes, if any",
 "type": "string"
   }
  }
 }
 </templatedata>

No editor or reader at any article ever sees that. I don't think it makes any sense to add a Wikidata link to the TemplateData.

Are you looking for a sort of magic infobox, so that you can type {{infobox}} and Wikidata fills in all the fields for you? That already exists, and it has nothing to do with TemplateData. Have a look at w:es:Jimmy Wales for an example of a long infobox that is mostly pulled from Wikidata.

BoldLuis (talkcontribs)

From your example : "description": "The template is used to identify claims in articles, particularly if questionable, that need a citation to

It would be translated to other language, I e. Spanish:

"description": "La plantilla se usa para identificar afirmaciones en artículos (and so on...)

So, this translation into Spanis of the template can be used in Wiktionary in Spanish, Wikipedia in Spanish, Wikibooks in Spanish... Translate once, use in several places.

On the other hand, this is seen in a forms way, when editing TemplateData.

BoldLuis (talkcontribs)

TemplateData editor method

This is the simpler way to add or edit TemplateData, possible for inexperienced users. </translate>

The TemplateData editor is a graphical user interface for adding and editing TemplateData. It is part of the TemplateData extension. It is accessible by going to any template's page (or documentation subpage) and clicking "Edit" or "Edit source".

After clicking "Edit" or "Edit source", you will see a button above the editing area and page title that says "Manage TemplateData".

Clicking this button will enter the TemplateData editor. If the page you are on already contains TemplateData, this will automatically show here. A screenshot of the TemplateData editing tool

Whatamidoing (WMF) (talkcontribs)

Because we don't have Global templates, it's unlikely that anything would get re-used in multiple places.

BoldLuis (talkcontribs)

We can use TemplateData in Wikidata for templates in all sister projects and so, the template documentation can be reused in multiple sister projects. Translate once, reuse several times. Also could be used the Wikifunctions wiki.

Reply to "Wikidata"
Pols12 (talkcontribs)

Hello MacFan4000,

You have split several paragraphs in order to reduce translate tag use. I think this is a bad idea because this make the text harder to read. Indeed, those one-sentence paragraphs are really strange; beside this make some sections (especially introduction) very big. Would you see any inconvenience to come back to previous paragraph splitting?

Pppery (talkcontribs)

I agree. Having slightly cleaner wikitext is not worth having a significantly less clean rendered output.

Ата (talkcontribs)

It is actually possible to split a paragraph into two translatable units without visual differences on the page.

Reply to "Paragraph splitting"

Set default value to the value of another template parameter

4
GoodMagician (talkcontribs)

In a template the default value of a parameter can be set to the value of another parameter. For example, parameter 2 can default to the value of parameter 1...

{{{2|{{{1}}}}}}

What is the correct way to represent this relationship in templatedata so that Visual Editor will handle the default properly? I've tried the approach below, but instead of showing the value of parameter 1 the template shows the number 1.


# This approach results in the wrong default behavior 
# when the template is added with Visual Editor

<templatedata>
{
  "params": {
    "1": {…},
    "2": {
      "label": "optional value",
      "description": "if this value is empty, show the value of parameter 1 instead",
      "suggested": true,      
      "default": "{{{1}}}"
    },
    "paramOrder": […],
    "format": "inline"
}
</templatedata>

Clump (talkcontribs)

My interpretation would be to indicate it as an alias.

Jonesey95 (talkcontribs)

Agreed. In the code shown above, 2= is an alias of 1=.

Tacsipacsi (talkcontribs)

However, there are situations where an alias doesn’t work. Imagine a template that links to the English Wikipedia. Its code is

[[w:{{{1}}}|{{{2|{{{1}}} }}}]]

—the first parameter (the article title) is required, while the second (the display text) is optional, and defaults to the article title. The two are clearly not aliases, but the default of parameter 2 is parameter 1. I usually write something like “parameter #1” to default and hope that the human reading it will understand what’s going on. Or describe the situation in description, and leave default empty. But neither of these workarounds is really a solution. Probably there should be a new key (mutually exclusive with default) that contains a parameter name (instead of literal text) the parameter defaults to. Support for this should be implemented in consumers like VisualEditor afterwards, of course.

Reply to "Set default value to the value of another template parameter"