Search code examples
mediawikimediawiki-extensionsmediawiki-templates

Hand over parameters from a MediaWiki template to a included one


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


Solution

  • 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