Reputation: 2497
Is it possible to get a template to inherit parameters from another template? I can't think of a better way to phrase the question so allow me to give an example.
Say you have two templates {{test1}}
and {{test2}}
that are being used on a page called "Test Page".
Template:Test1:
{{{par1}}}<br>
{{{par2}}}<br>
{{test2}}
<!--{{test2|par3={{{par3}}}|par4={{{par4}}}}}-->
Template:Test2:
{{{par3}}}<br>
{{{par4}}}<br>
Test Page:
{{test1|par1=aaa|par2=bbb|par3=ccc|par4=ddd}}
So what I would like to have happen is have it display:
aaa
bbb
ccc
ddd
The normal way of doing this would be to include the line that is commented out in Template:Test1
. Is there anyway to get it to automatically pass the parameters though? For something this mundane, it is isn't a problem to explicitly say par3={{{par3}}}
but when the templates get much more complex, it could be REALLY helpful. Any tips are most appreciated.
Upvotes: 3
Views: 623
Reputation: 1133
First, your Test1 template invoking Test2 with no parameters makes no sense. You invoked it as {{test2}} (no parameters).
If you want page-global variables, I would suggest using Mediawiki Variables plugin. http://www.mediawiki.org/wiki/Extension:Variables
Additionally, it is good practice to "default" template parameters with a vertical bar, such as {{{par1|}}} or {{{par2|None}}}. Otherwise, if the parameter isn't given, the resulting wikitext will be the parameter name with the braces. For example: {{{par1|}}} returns a blank string if that parameter isn't given, but {{{par1}}} actually produces "{{{par1}}}" as the string if the parameter is absent, which probably isn't useful.
Back to my example using Variables, I have adapted your example (par1 is the argument going into test1 template, par2 is the argument going into test2 template):
Template test1 becomes:
{{{par1|}}}<br/>
{{#vardefine: par2|{{{par2|}}} }}
{{test2}}
Template test2 becomes:
{{#var:par2}}<br/>
Upvotes: 0
Reputation: 28160
You can use
{{test2|{{{arg1}}}={{{par1}}}|{{{arg2}}}={{{par2}}}}}
in test1
, and call it as
{{test1|arg1=par1|arg2=par2|par1=foo|par2=bar}}
but you can probably save a fair amount of sanity by just waiting for Lua. (It has been already deployed on some smaller Wikipedias, and will be deployed on all in March, so it is not a long wait.)
Upvotes: 1
Reputation: 97555
What you're trying to describe is argument forwarding. No, this is not possible with mediawiki templates alone.
The new Lua engine (available to test as Extension:Lua, eventually aiming to become part of the core) that is in development appears to make this possible.
Upvotes: 2