Semantic Mediawiki - Passing a variable to a template

996 views Asked by At

I have the result of a semantic query. For one of the properties, a comma separated list, I want to separate each item and pass it as a parameter to a template. However, I am struggling to find a way to do this.

For example;

Query:

{{#ask: [[Category:Something]] [[Has title::Somethingelse]]
| mainlabel=-
| ?Has property
| link=none
| format=template
| template=plainText
}}

The plainText template will have the result, which is a comma separated list. Now, from the plainText template I would like to separate the comma separated list and put each value as a parameter into another template.

I have tried using {{#arraydefine:key|values|delimiter|options}} but when I pass {{#arrayindex:key|0}} to the template, the value is not passed. The whole array is passed separated by 0. I have also tried using {{#vardefine: etc but this also does not pass the variable.

My question boils down to, how to pass a variable to a template?

Thanks,

1

There are 1 answers

0
Wolfgang Fahl On BEST ANSWER

The separation needs to be done in the template. If you use anonymous args like in http://semantic-mediawiki.org/wiki/Template:Query_output_demo

Your params can be fetched with defaults like this:

{{{1|param1default}}} {{{2|param2default}}} ...

Now one of your params is a comma separated list. You might want to use the

#explode

parser function to get to the different parts of the CSV. Lets assume the second parameter has your csv then:

{{#explode:{{{2}}}|;|0}}
{{#explode:{{{2}}}|;|1}}
...

will provide the fields.

For this to work you need the extension

https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions##explode

and to enable it according to the instructions there.