2

I have a template that takes parameters called "name" and "type".

I am currently attempting to call that template and pass it the transcluded contents of a page called Input1 that simply says:

name=Thing|type=Whatsit

I am calling the template this way: {{TemplateName|{{:Input1}}}}

However the template is simply receiving the text "name=Thing|type=Whatsit". It is not parsing the text as parameters, as if I had invoked it this way:

{{TemplateName|name=Thing|type=Whatsit}}

Is there any way to coax MediaWiki to see the page's contents as actual parameters, setting {{{name}}} and {{{type}}} on that basis? I had big plans for being able to use another template, Foreach, to create many calls to a template this way, passing it Input1, Input2, etc.

user1134918
  • 129
  • 1
  • 8
  • I don't think that this is possible without an additional extension. I do think that with Scribunto extension this is doable. – Sorawee Porncharoenwase Dec 26 '15 at 16:47
  • Thanks for the comment @sorawee-porncharoenwase, you reminded me that I wanted to leave a comment here when I arrived at a final answer to my problem. My goal was to have pages which contained information that could be plugged into different templates via transclusion, so that you could view the same set of data in different formats or views, provided by each template. I accomplished that by creating those pages as not just bare data, but as actual template calls, and then by calling the pages themselves as templates in order to pass them a "switching" parameter. [1/2] – user1134918 Dec 27 '15 at 17:24
  • 1
    In other words, the pages' contents are something like `{{SwitchingTemplate|mode={{{mode|standard}}}|name=Thing|type=Whatsit}}`. I then call these pages from other pages using the markup "{{:page1|mode=table}}" or "{{:page1|mode=printable}}". SwitchingTemplate looks at "mode" and then passes on the relevant parameters that were passed into it (there's a lot more than "name" and "type") to the template that "mode" is referring to with statements like: `{{#ifeq:{{{mode}}}|standard|{{StandardView|name={{{name}}}|type={{{type}}}}}`, `{{#ifeq:{{{mode}}}|table|{{TableView|name={{{name}}}}}}}`, etc. – user1134918 Dec 27 '15 at 17:26

1 Answers1

2

It is not possible to transclude the contents of a page to be used as parameters to a template. MediaWiki first parses the structure of the template expression, i.e. the '{{', '|' and '}}'. Subsequently it expands the templates inside that expression, but if this expansion contains a '|' it is interpreted as a literal '|' and not a parameter separator. Hence the number of parameters can no longer change. This behavior used to be necessary to make the {{!}} template work, which was used to insert a literal '|' in a template parameter.

However, by changing the order of the transclusions, you can still do exactly what you want. Template parameters can be used to construct the name of another template. So, you can pass the name of the template as a parameter to the page that contains your parameters: {{:Input1|TemplateName}}. Your 'Input' page would then be written as:

{{{{{1|Standard}}}
|Name=Input1
|Param1=Value1
|Param2=Value2
}}

So transcluding the page containing the parameters as {{:Input1|TableView}} would yield the desired result:

{{TableView
|Name=Input1
|Param1=Value1
|Param2=Value2
}}
bcmpinc
  • 3,202
  • 29
  • 36