Extension talk:TemplateData

About this board

Pull values from the TemplateData block?

2
BCreegan (talkcontribs)

I would like to create a DPL that lists all the templates in a category, along with the description listed inside their data block. Is this possible?

Thiemo Kreuz (WMDE) (talkcontribs)
Reply to "Pull values from the TemplateData block?"

TemplateData Editor suggested values input field not showing

7
MrSmith35 (talkcontribs)

So I've been learning to make templates over the last week or so, manually at first then I started to read about the TemplateData Editor and the possibility of adding a limited range of suggested parameter values by way of the suggested values field. However it just will not show whether I use the editor on an existing template or a new one from scratch. I'm running a recently updated MW 1.37.2 (previously 1.35) with extension versions that came with it, PHP 7.4.28, TemplateData Extension 0.1.2. Tried changing the skin, I normally use Citizen (1.17.4) but tried it with the vanilla, as installed, Vector 1.0.0, still no joy. I have updated the TemplateData Extension to 0.1.2 (3e7e798) 06:04, 1 June 2022. But alas nothing. Tried it with the 2010 wikitext editor, still nothing. I went onto Wikipedia and tried their TemplateData Editor which worked as advertised, so I know what to expect. I did find something on Phabricator about a bug with the suggested values filed which was reported April 2021, but that was different.

At my wits end - any suggestions?

Thanks

Thiemo Kreuz (WMDE) (talkcontribs)

At the moment the suggested values feature is still opt-in. This will change in the near future. Until then you need to add $wgTemplateDataSuggestedValuesEditor = true; $wgVisualEditorTransclusionDialogSuggestedValues = true; to your LocalSettings.php. I hope that helps.

MrSmith35 (talkcontribs)

Thanks for your quick reply Thiemo, much appreciated, worked a treat.

The suggested parameter values list appears as expected and I can edit existing lists. The drop down menu also works correctly in the insert template dialogue.

I have one minor issue, the insert Template dialogue works well except in my named User namespace. The dialogue appears and goes through the motions of doing what it's supposed to but after I hit apply no template is added to the article, but no error dialogue or warning appear. Though this is not that serious as I generally will be using templates in the Main namespace, is there a separate setting that I need to toggle to enable the dialogue in my User namespace?

Thiemo Kreuz (WMDE) (talkcontribs)

Oh, that sounds like a bug. Unfortunately I can't reproduce it on my machine. Can you provide more information and maybe report it?

MrSmith35 (talkcontribs)

Hi,

Yes I could, what do you need to know, please keep in mind I am a complete novice wrt MediaWiki and stuff like php. I can just about follow along with good instructions otherwise I get lost pretty quickly. Are there are specific logs I could easily find that might help, I couldn't see anything in the public logs on the wiki. My set up is on a Synology NAS - a custom install of MediaWiki as I couldn't get the Synology supported app working. I run it on Apache 2.4 with PHP 7.4 and MariaDB 10.

Thiemo Kreuz (WMDE) (talkcontribs)

Does something appear in your browser's JavaScript console (Ctrl+Shift+I)? I currently don't have a better idea where to look for this kind of error. Maybe you continue and see if the issue persists, and report back later?

MrSmith35 (talkcontribs)

Hi,

Yes there is an output in the console but nothing that comes up as an error related to the actions when adding a template neither in the Main namespace nor in the User namespace, both consoles look pretty much the same.

The problem I'm seeing might be completely unrelated to the TemplateData extension in as much as I did previously have an error in the User namespace adding pages that had a "/" in their name eg User:MrSmith35/sandbox - I read that on some setups the slash could cause errors with Apache 2.4, but I fixed that by adding something to the Apache server config - what I'm seeing with templates not rendering might be something to do with how my server is configured.

I don't need templates in the user namespace so for now I can live with it, see what happens. If you do think of anything that might help resolve this or come up with a suggestion of where we might find the error logging, then I'm more than happy to help in any way I can. If I get time I might try a docker install of MW on my Synology which might give me an easier ride through the installation process than the hodgepodge of methods I had to use to get it working. If the error occurs in docker then it's probably worth investigating.

Thanks again for your help and the great work on the extension.

Reply to "TemplateData Editor suggested values input field not showing"

TemplateData editor and paramOrder

3
MLRodrigue (talkcontribs)

I have a template that I created in MW 1.31 (TemplateData 0.1.2). The TemplateData editor does not create the paramOrder object, but the order still works, because it adheres to the order in which the parameters are defined in the source code.

However, in my MW 1.35 this no longer works. The params are ordered based on their name instead. Since the editor does not create the paramOrder, I now have to manually add it in the source code for each template. I would like to avoid that and don't know if it's just an issue in my wiki that the paramOrder object is not created automatically by the editor?

Thiemo Kreuz (WMDE) (talkcontribs)

I wasn't involved back then and can't tell when this broke, and where. It's potentially related to an unrelated change in Parsoid. But I'm aware of this issue. We fixed it just recently via gerrit:700350. This is part of MediaWiki 1.37, but not earlier, unfortunately. I think the best option you have (other than using 1.37) is to add a specific paramOrder to each template. The TemplateData editor isn't designed to do this automatically.

MLRodrigue (talkcontribs)

Okay, then I know what to do. Thanks for the prompt answer!

Reply to "TemplateData editor and paramOrder"

Including templatedata within another templatedata

5
Summary by Tinss

Use the #tag directive on the root templatedata and then use it like a normal template.

Tinss (talkcontribs)

I have several templates on my wiki that define the exact same fields through some sort of inheritance pattern/mixin. When updating those fields in the parent templates, I need to go over each child's templatedata to update the doc.

Is there a way to include a templatedata structure within another one?

Thiemo Kreuz (WMDE) (talkcontribs)

In theory, yes. Since the <templatedata> block is part of an otherwise normal wikitext page, it's possible to create a template that somehow generates this <templatedata> block's source code. And templates can call each other. However, this does have disadvantages, like not being able to use the build-in TemplateData editor any more.

A specific TemplateData feature to do something like this doesn't exist at the moment.

Tinss (talkcontribs)

Thanks for the advice. Indeed that would make it work. Having a JSON parameter that lets a user merge one templatedata block into another would be a better solution though. When I get some time, I'll look into adding that feature to the code base.

Thiemo Kreuz (WMDE) (talkcontribs)

I understand the idea, but don't think it can be done this way. Mostly for performance reasons as well as complexity. The existing mechanisms to give pages access to each other are templates and Lua modules. Introducing a new way is not a simple task.

Tinss (talkcontribs)

Got it. I ended up doing of bit of experimentation and manage to get it to work using templates only. This trick is to define your root templatedata using the #tag directive so it does not trigger an invalid JSON error.

For a live example, see my wiki.

Cannot add complete/concise TemplateData to templates that accept many numbered parameters

2
Summary by Thiemo Kreuz (WMDE)
Sdkb (talkcontribs)

For templates like w:Template:Multiple image and w:Template:Maplink, there can be an arbitrary number of parameters for images in the collage or points on the map. TemplateData does not currently seem to have a way to handle this; the best that can be done is to add TemplateData manually up to a dozen or so, which covers most use cases. However, this is tedious, first of all, and it clutters the documentation by creating a bunch of repetition. There are a lot of templates like this, so I'd like to see this fixed at some point.

Thiemo Kreuz (WMDE) (talkcontribs)

Yes, this is a known limitation, see phab:T54582. I'm afraid there are currently no plans to work on this.

Reply to "Cannot add complete/concise TemplateData to templates that accept many numbered parameters"

Small bug with warning message

6
Summary by Whatamidoing (WMF)
Sdkb (talkcontribs)

When I edit a template that has a TemplateData block on its documentation page, a warning appears ("Please note: there is already a TemplateData block on the related page"). However, when I edit a section of the documentation when there is already a TemplateData block in a different section, no such warning appears. This isn't the biggest issue, but it'd be nice to rectify. (It'd also be nice if, instead of a distracting warning, clicking on the button just redirected you to edit the documentation page; this would reduce both banner blindness and errors.)

Whatamidoing (WMF) (talkcontribs)

I think I've followed all of that, but could you give me a link so I can try it out?

Sdkb (talkcontribs)
Whatamidoing (WMF) (talkcontribs)

Right now:

  • If you edit the 'wrong' page, it warns you that TemplateData is present on the 'right' page.
  • If you edit a section of the 'right' page, it does not warn you that TemplateData is present in a different section of this page.

You propose:

  • (No change for the first point)
  • Adding a warning that TemplateData is present in a different section.

I wonder if this might be more annoying overall. There are almost 50 sections on that /doc page. I imagine that most people aren't trying to change the TemplateData (unless they're editing the TemplateData section itself). I think adding this warning might produce complaints about an "irrelevant" warning. I can imagine editors saying "Why is it telling me that TemplateData is in another section? I already know that! If I cared about TemplateData, I'd be editing the section named ==TemplateData==!"

Sdkb (talkcontribs)

Yeah, I think that speaks somewhat to my point in the parenthetical above. There's no strong need to have it at the main template, either; editors could make a similar point about it being irrelevant there. Instead of the existing workflow, I think it would be better if there was initially no warning, but if someone clicks the Manage TemplateData button, a notice pops up saying "There is already a TemplateData block on the documentation page/in another section. Click proceed to edit it there (you will lose any unsaved work)." That would be better since it'd then only affect people actually trying to edit the TemplateData, so the banner blindness would be significantly reduced.

Tacsipacsi (talkcontribs)

The proposed solution with the TemplateData editor adding the warning (instead of the static warning banner) looks good, with one exception: if someone adds a TemplateData block manually, without the wizard, they’re not warned. Probably this use case is rare, but possible; for example importing TemplateData from another wiki/page is much more convenient using copy&pasting wikitext than with retyping everything in the wizard.

Reply to "Small bug with warning message"
Sdkb (talkcontribs)

At least on the en-wiki implementation, the difference between "string", "line", and "content" is not particularly clear, and the documentation table doesn't help very much. Would it be possible to clarify it further?

Thiemo Kreuz (WMDE) (talkcontribs)
Sdkb (talkcontribs)

Thanks! I still don't feel like I have a full sense of things (maybe some examples could help?), but the line breaks note is definitely an improvement. Good luck with your work on this!

Whatamidoing (WMF) (talkcontribs)

The words "String" and "Line" mean whatever those words mean to coders. "Content" means what an editor thinks it means (approximately "anything goes"). The distinction is mostly not enforced by software (yet, but I've been saying that for years, and I expect to be saying that years from now).

Reply to "Types unclear"

"One of several" type

2
Summary by Thiemo Kreuz (WMDE)
Sdkb (talkcontribs)

I was definitely pleased to see the suggested values feature rolled out. I think it might be helpful to also have a type for parameters that should be one of several values but nothing else. Sorta like boolean only for more than two.

Thiemo Kreuz (WMDE) (talkcontribs)

We are happy to hear you like it. A more strict version is still discussed in phab:T53375. For now the team decided to go with the most flexible version for a multitude of reasons. It already solves the vast majority of use-cases, without ever blocking anybody. You can find more about the reasoning in phab:T271825 and it's sub-tickets.

Reply to ""One of several" type"

After import, a template requires a manual re-save for TemplateData to work

2
MLRodrigue (talkcontribs)

When I import a template that uses TemplateData to another wiki, the template description and parameters are not shown when adding the template to a page via VisualEditor.

Noteː The parameters in question are either required or suggested, so should show up immediately when the dialog opens.

To make the template work, I have to go to the imported template and re-save it (e.g., by adding an empty space to the template page). After that, the template works correctly in the imported wiki and the parameters and template description are available.

Is this to be expected?


Such templates that use TemplateData are supposed to be imported by wiki users who have no access to maintenance scripts.

Tacsipacsi (talkcontribs)

As noted in Help:TemplateData#Limitations and feedback, a null edit is sometimes required for TemplateData to update. This can happen while importing as well. However, no actual edit (and thus no page history spam) is needed; and if you have Pywikibot set up, you can use touch.py to automate the null edits (this requires no direct shell access to the server).

Reply to "After import, a template requires a manual re-save for TemplateData to work"

Big task: Translating template content

2
Summary by Whatamidoing (WMF)

Off topic

BoldLuis (talkcontribs)

I tried to translate the content of the template w:template:Infobox organization in the article w:Open Source Security Foundation. I have to add to parameters by hand, related to location (in the Spanish version "ciudad de sede") and region (also "region" in the template in Spanish). Why?. I am going to try to find the reasons for this. Specially, when the field is called with the same name in both local templates.

Whatamidoing (WMF) (talkcontribs)
Return to "TemplateData" page.