Many, many times, I have wanted to create a template that takes a list of values, and displays them in a table, each on their own line. I've tried hiding the comma in a span, but that breaks the table.
<span style="display:none;">{{#arraymap: {{{programmers|}}}|,|x|</span><!--
-->{{!}} Programmer: {{!!}} x
{{!-}}<span style="displ开发者_运维知识库ay:none;">}}</span>
Is there a method of hiding the delimiter and still getting a table, or perhaps, is there a separate way to do this altogether?
If you want a full simplified testcase, I have the following input:
{{authors|programmers=Ryan Scheel, Ryan Dean}}
and I want the following output:
{| class="wikitable"
|-
! colspan="2" style="text-align:center;" ! Authors
|-
| Programmer: || Ryan Scheel
|-
| Programmer: || Ryan Dean
|}
or in template form:
{{{!}} class="wikitable"
{{!-}}
! colspan="2" style="text-align:center;" ! Authors
{{!-}}
{{!}} Programmer: {{!!}} Ryan Scheel
{{!-}}
{{!}} Programmer: {{!!}} Ryan Dean
{{!}}}
I solved your problem by passing an empty 5th argument to the function[1]. This argument defines what to replace the delimiter with.
{{#arraymap: Ryan Scheel, Ryan Dean|,|x|<nowiki />
{{!-}}
{{!}} Programmer: {{!!}} x
|<!-- empty 5th parameter -->}}
expanded result will be as following:
{|
<nowiki />
|-
| Programmer: || Ryan Scheel<nowiki />
|-
| Programmer: || Ryan Dean
|}
I slightly modified your example for my own convenience during my tests, feel free to adjust it to your taste. I put the |-
(HTML <tr>) before the |
(HTML <td>) because it is more logical.
More important, as you may already know, arguments of parser functions are trimed[2]. The problem is that wiki tables markup ({|
, |-
, etc.) should be at the beginning of the lines of the source, otherwise it is not interpreted[3]. So, in order to insert a linebreak, in this example before the |-
's, I used the pretty <nowiki />
trick ;-)
As a side note, your line ! colspan="2" (...) ! Authors
has a mistake, the !
before "Authors" has to be a |
instead.
[1] documentation at http://www.mediawiki.org/wiki/Extension:Semantic_Forms/Semantic_Forms_and_templates
[2] contrary to unnamed parameters of templates!
[3] The only exception, as far as I know, is that you can put spaces and HTML comments before.
精彩评论