Page MenuHomePhabricator

Make current variables available for transcluded templates.
Open, LowPublicFeature

Description

Author: rene.kijewski

Description:
It would be nice, if there would be a easier way to access the variables the "parent" template has received.

Example:

  • Template {{A}} transcludes one out of three templates (let’s call them {{A/n}}), depending on a parameter it was "called" with.
  • Overall, {{A/n}} are all the same, save some minor differences like their background color or the order of the lines in the infobox they are part of.
  • Thus {{A/n}} have to get the same parameters. And especially they have to get the same parameters as {{A}} was "called" with. Only the one distinguishing parameter may not be needed.

By now, {{A}} would be something like
{{switch:{{{1}}}

a={{A/1par0={{{par0}}}..parM={{{parM}}}}}
b={{A/2par0={{{par0}}}..parM={{{parM}}}}}
c={{A/3par0={{{par0}}}..parM={{{parM}}}}}

}}.
There is much needless overhead in the source code, which could be rather good evaded, if {{A/n}} would be aware of {{A}}’s parameters, making {{A}}’s code:
{{switch:{{{1}}} |a={{A/1}} |b={{A/2}} |c={{A/3}} }}.

Proposal:
There would be three options, how to make {{A/n}} aware of {{A}}’s parameters:

  • Always give the own parameters to transcluded templates.
  • Add a new parameter accessing prefix for {{A/n}}: {{{..:par0}}}.
  • Transclude {{A/n}} differently: {{include:A/1}}.

I would prefer the third option, because it would likely 1) be the easiest to implement, 2) have least overhead and 3) be the most explicit variant.

Main beneficiaries would be beasts like [[Template:Location map]].


Version: unspecified
Severity: enhancement

Details

Reference
bz22636

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 11:06 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz22636.
bzimport added a subscriber: Unknown Object (MLST).

Hello René, how do you want to implement the third option with {{include:A/1}}? To send the parameters of {{A}} to the transcluded template {{A/1}} and {{A/1}} can access for example to {{{par0}}} of {{A}} easily by write {{{par0}}}.

banaticus wrote:

http://en.wikipedia.org/wiki/Template:Infobox_Weather/concise_F takes parameters and passes them to http://en.wikipedia.org/wiki/Template:Infobox_Weather

location = {{{location}}}

In here, the concise_F template takes a possible location parameter (if present) and passes it to the location parameter which is part of the called (parent) Infobox_Weather template.

happy.melon.wiki wrote:

Essentially, any parameters which are not explicitly overridden should be passed through:

[[Page]]:

{{outerTemplate|1=foo|2=bar}}

[[Template:OuterTemplate]]:

{{innerTemplate|2=quok|4=nada}}

[[Template:InnerTemplate]]:

1: {{{1}}}, 2: {{{2}}}, 3: {{{3}}}, 4: {{{4}}}

Should output

1: foo, 2: quok, 3: {{{3}}}, 4: nada

Whether to enable that parameter fallthrough by default, or only in specific cases, is another question.

But there you maybe have side effects, when some inner templates uses the same parametername as the outer template. Because when the inner template is not designed to be the inner template and some parameters with the same name but not the same usage will be overridden. I would suggest, to add prefixes to determine the „namespace“. For example {{{i:<name>}}} if you do not want to override it (default) or {{{o:<name>}}} if you only want to use the outer parameter or {{{c:<name>}}} to implement your way.
Is this the suggestion with the {{{include:…}}} from René?

rene.kijewski wrote:

(In reply to comment #4)

...
Is this the suggestion with the {{{include:…}}} from René?

Yes, exactly.

But what does happen when you input {{include:…}} ? Do you send your parameters to the parameters of the inner template?

rene.kijewski wrote:

(In reply to comment #6)

But what does happen when you input {{include:…}} ? Do you send your parameters
to the parameters of the inner template?

Sorry, I did not understand your question. Could you make an example?
Did you mean whether your parameters should be transcluded to _all_ inner templates? I'd say no.

Okay… I have two templates. One template generate a tablecontainer and one template for each row (e.g. the Template table and row). In the table you could switch some columns on/off and you set the rows which should know the visible columns. My idea is, that the row can ask the table for the visible columns. But the question how the row can get the information.

For example the table template shows always an id and a name column. Optionally you could show a country column.
At the moment every row need a parameter for „showcountry“:
{{table | showcountry = yes | content = {{row|id=0|name=Hello World|country=Vulcan}}{{row|id=1|name=42|showcountry=yes}}}}
In the second row you can't leave country blank (column will be invisible) or you have to set, that there is a country column. But when the template row can ask the template table if there is a country column you could save one parameter.

But my problem is: What will the include-option do? And where do you want to place this option?

rene.kijewski wrote:

(In reply to comment #8)

I thought {{include:...}} as a kind of shortcut for having to include every parameter explicitly.
I would be nice, if the inner child could ask some outer template for its parameters, too.

Both would fulfill the same interest. I have no strong opinion, which option should be implemented (maybe both?). I'd leave it to the developers to tell, which would be easier to implement or have less overhead.

Can you give me an example of the implementation of yout include suggestion? For me the {{....}} are confusing, because this would be a template implementation and we want to add a feature to the parameters actually.

Okay, what is the status of this feature?

Aklapper changed the subtype of this task from "Task" to "Feature Request".Feb 4 2022, 11:01 AM
Aklapper removed a subscriber: wikibugs-l-list.