-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

4

2 回答 2

2

最后我想出了以下解决方案:

DPL 有一个附加模板#dplreplace。我正在使用它来解析我的参数。

调用模板:

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

在模板中,我替换了:by=;by {{!}}

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

注意:{{!}}是一个模板,由|.

问候;
射线

于 2015-05-09T10:19:25.063 回答
1

也许我误解了您的问题,但您可以将参数传递给 DPL,就像您传递给模板或另一个解析器函数一样。在大多数情况下,您可能希望添加一个空的默认值:

我的模板:

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

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

像这样称呼它:

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

也可以使用缺少的参数:

{{myTemplate
  |category=foo
  |mypara1=bla
  |mypara2=lala
}}
于 2015-05-08T08:05:31.360 回答