Jump to content

Topic on Extension talk:TemplateData/Flow

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.