-2

テンプレートとして使用できるMediaWiki 拡張DynamicPageList (サードパーティ)を使用しています。

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

より多くのパラメーターを使用するテンプレートの 1 つでこのテンプレートを使用しようとしました。

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

myTemplateは次のようになります。

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

パラメータはわかっていますが、#dpl:は 1 つまたは複数のパラメータを使用できます。

パラメータを#dpl:から分離するにはどうすればよいですか? そして、 #dpl:に属するパラメーターを渡すにはどうすればよいですか?

ありがとう、
レイ

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 に答える