-2

I'm using the MediaWiki extension DynamicPageList (third-party) which can be used as a template:

{{#dpl:
|category=foo
|notcategory=bar
}}

I try to use this template in one of my templates which uses more parameter e.g.:

{{myTemplate
|category=foo
|notcategory=bar
|mypara1=bla
|mypara2=lala
}}

myTemplate looks like this:

do something with mypara1
...
do something with mypara2
...
{{#dpl:
|category=foo
|notcategory=bar
}}

I know my parameters but #dpl: can use one or many parameters.

How can I separate my parameters from the #dpl: ones? And how can I just hand over the parameters which belongs to #dpl:?

Thanks,
Ray

Ray
  • 99
  • 1
  • 7
  • Why don't you just pass them on? – leo May 08 '15 at 08:02
  • Well, the question is how? Sometimes I have only a `category`, sometimes two, or I can use a `namespace` parameter or I can use a conbination of all of them... – Ray May 08 '15 at 08:06

2 Answers2

2

Finally I came up with the following solution:

DPL has an additional template #dplreplace. I'm using this to parse my parameters.

Call the template:

{{myTemplate
  | filter=category:foo;notcategory:bar
  | mypara1=bla
  | mypara2=lala
}}

In the template I replace the : by = and ; by {{!}}.

{{#dpl:
  | {{#dplreplace: {{#dplreplace: {{{filter}}} | /:/ | = }} | /;/ | {{!}} }}
  | ordermethod = sortkey
  | suppresserrors = true
}}

NOTE: {{!}} is a template which is replaced by |.

Regards;
Ray

Ray
  • 99
  • 1
  • 7
  • You don't even necessarily need the inner `#dplreplace`: named parameter values (but not names) can contain equals signs just fine, as in `filter=category=foo;notcategory=bar`. Mind you, readability may be a different matter. – Ilmari Karonen May 09 '15 at 10:31
1

Maybe I'm misunderstanding your issue, but you can just pass the parameters on to DPL, just like you would to a template, or another parser function. You might want to add an empty default in most cases:

myTemplate:

do something with {{{mypara1}}}
do something with {{{mypara2}}}

{{#dpl:
  |category    = {{{category|}}}    <!-- default to empty string -->
  |notcategory = {{{notcategory|}}} <!-- default to empty string -->
}}

Call it like this:

{{myTemplate
  |category=foo
  |notcategory=bar
  |mypara1=bla
  |mypara2=lala
}}

Will work with missing parameters too:

{{myTemplate
  |category=foo
  |mypara1=bla
  |mypara2=lala
}}
leo
  • 8,106
  • 7
  • 48
  • 80
  • Hi Leo, many thanks for your answer. Your solution will cover most of the cobinations but it won't work if I use one parameter twice which is allowed in DPL. Regards, Ray – Ray May 08 '15 at 09:15
  • No, template variables in MediaWiki must be unique. You have to either separate them (`category_1`, `category_2`), or use a parser function to split a string with several ones (`categories=aaa,bbb,ccc`) – leo May 08 '15 at 12:19
  • Hi Leo, with your keyword _parser function_ in mind I came up with a solution which fulfill my requirements. See my one answer. Thanks Ray – Ray May 09 '15 at 10:06