#arraymap 输出中不包含分隔符

发布于 2024-12-07 05:11:20 字数 844 浏览 1 评论 0原文

很多很多次,我都想创建一个模板,它接受一个值列表,并将它们显示在一个表中,每个值都在自己的行上。我尝试过将逗号隐藏在跨度中,但这会破坏表格。

<span style="display:none;">{{#arraymap: {{{programmers|}}}|,|x|</span><!--
-->{{!}} Programmer: {{!!}} x
{{!-}}<span style="display:none;">}}</span>

是否有一种隐藏分隔符并仍然获得表格的方法,或者是否有一种单独的方法可以完全做到这一点?

如果您想要一个完全简化的测试用例,我有以下输入:

{{authors|programmers=Ryan Scheel, Ryan Dean}}

并且我想要以下输出:

{| class="wikitable"
|-
! colspan="2" style="text-align:center;" ! Authors
|-
| Programmer: || Ryan Scheel
|-
| Programmer: || Ryan Dean
|}

或以模板形式:

{{{!}} class="wikitable"
{{!-}}
! colspan="2" style="text-align:center;" ! Authors
{{!-}}
{{!}} Programmer: {{!!}} Ryan Scheel
{{!-}}
{{!}} Programmer: {{!!}} Ryan Dean
{{!}}}

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="display: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
{{!}}}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白衬杉格子梦 2024-12-14 05:11:20

我通过将空的第五个参数传递给函数[1]解决了您的问题。该参数定义用什么来替换分隔符。

{{#arraymap: Ryan Scheel, Ryan Dean|,|x|<nowiki />
{{!-}}
{{!}} Programmer: {{!!}} x
|<!-- empty 5th parameter -->}}

扩展结果如下:

{|
<nowiki />
|-
| Programmer: || Ryan Scheel<nowiki />
|-
| Programmer: || Ryan Dean
|}

为了在测试过程中方便起见,我稍微修改了您的示例,请随意根据您的口味进行调整。我将 |- (HTML ) 放在 | (HTML ) 之前,因为这样更符合逻辑。

更重要的是,您可能已经知道,解析器函数的参数会被修剪[2]。问题是 wiki 表标记({||- 等)应该位于源代码行的开头,否则不会被解释[3]。 ,为了在 |- 之前插入换行符,我使用了漂亮的 技巧;-)

因此 注意,你的行! colspan =“2”(...)! Authors 有一个错误,“Authors”之前的 ! 必须改为 |

[1] 文档位于 http://www.mediawiki.org/wiki/Extension:Semantic_Forms/ Semantic_Forms_and_templates

[2] 与模板的未命名参数相反!

[3] 据我所知,唯一的例外是您可以在前面添加空格和 HTML 注释。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文