5

我需要一个语义查询结果表模板,在该模板中,我可以在同一个表中同时获得某些列的换行符分隔的单元格结果和逗号分隔的列。

例如,如果我使用标准format=broadtable,则结果在所有列的表格单元格内由换行符分隔:

{{#ask:[[Category:Items]]
|?Description
|?Models
|?Addons
|format=broadtable
}}

如果我创建一个模板,我所能完成的只是一个逗号分隔的结果:

<includeonly>
{| class="wikitable sortable"
 ! style="width: 30%;" | Page
 !! style="width: 30%;" | Description
 !! style="width: 20%;" | Models
 !! style="width: 20%;" | Addons
 |-
</includeonly>

{{#ask:[[Category:Items]]
|?Description
|?Models
|?Addons
|format=template
|template=QResTemplate
}}

<includeonly>
|}
</includeonly>

这是 QResTemplate:

<includeonly>
 | {{{1}}} || {{{2}}} || {{{3}}} || {{{4}}}
 |-
</includeonly>

每个项目都有多个模型和插件,因此表中的第 3 列和第 4 列需要其中一个以逗号分隔,而另一个以换行符分隔。

如果我在 {{{3}}} 之后添加一些东西,比如换行符,它会添加到表格行的最后一个模型之后,而不是我想要的每个模型之后。

4

1 回答 1

2

Use Extension:Arrays to format your comma separated outputs as you want:

<includeonly><!--

       store arrays

 -->{{#arraydefine:models|{{{3}}}}}<!--
 -->{{#arraydefine:addons|{{{4}}}}}<!--

       print row

 -->
 | {{{1}}} || {{{2}}} || {{#arrayprint:models|<br/>}} || {{#arrayprint:addons|, }}
 |-
</includeonly>

First you store both lists as arrays. arraydefine assumes that your list is comma separated, unless you specify somthing else. Then you print your arrays again with #arrayprint, but this time you can decide how you want those values to be separated.

If you can't use commas (e.g. because some value contains a comma, you can add e.g. sep=¤ to your ask query, and then do {{#arraydefine:models|{{{3}}}|¤}} to tell arraydefine that you are using a different separator.

于 2014-08-31T10:41:17.433 回答