Formatting a Semantic MediaWiki query result template with new cell characters

I need a semantic query result table template in which I can have both the cell results of a cell with row separators for some columns, and comma-separated columns in one table.

If I use the standard format = widescreen , for example, the result is separated by newline characters inside the table cells for all columns:

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

If I create a template, all I can accomplish is a comma separated result:

 <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> 

Here is the QResTemplate:

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

Each element has several models and additions, so in table 3 and 4 in the table, I need one of them to be separated by a comma and the other to be divided into a new line.

If I add something after {{{3}}} as a new row, it is added after the last model in the table row, and not after each model as I want it.

+5
source share
1 answer

Use Extension: Arrays to format 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 save both lists as arrays. arraydefine assumes your list is comma separated unless you specify anything else. Then you print your arrays again with #arrayprint , but this time you can decide how you want these values ​​to be separated.

If you cannot use a comma (for example, because some value contains a comma, you can add, for example, sep=Β€ to your query request, and then do {{#arraydefine:models|{{{3}}}|Β€}} to tell arraydefine that you are using a different delimiter.

+2
source

Source: https://habr.com/ru/post/1201465/


All Articles