在模板调用中传递管道

问题描述 投票:0回答:1

我正在尝试从模板内调用模板。我传递的参数值包含一个正斜杠,我想用管道替换该斜杠,以便将该值分为两个参数。

例如,

|nrs_reference=RS38/4
,我想将其传递为
{{Sasines full|RS38|4}}
,所以RS38是
{{{1}}}
,4是
{{{2}}}

但是我用这段代码得到的是

RS38|4
作为
{{{1}}}

{{#if: {{{citation_template|}}}
    |{{#ifeq:{{{citation_template|}}}|NLS full
        |* {{NLS full|title={{{nls_title|}}}|id={{{nls_id|}}}|collection={{{nls_collection|}}}|url={{{nls_url|}}}}}
    |{{#ifeq:{{{citation_template|}}}|Sasines full
        |* {{Sasines full|{{#replace:{{{nrs_reference|}}}|/|{{!}}}}}}
        |* {{#if:{{{citation_template_parameter|}}}|{{{{{citation_template|}}}|{{{citation_template_parameter|}}}={{{citation_template_parameter_value|}}}}}
        |{{#if:{{{volume|}}}|{{{{{citation_template|}}}|volume={{{volume|}}}}}
        |{{{{{citation_template|}}}}}
        }}
        }}
        }}
        }}{{#set: Has citation template=Template:{{{citation_template|}}}}}
            |{{#if: {{{full_citation|}}}|* {{{full_citation|}}}}}
}}

我也尝试过

{{Sasines full|{{#replace:{{{nrs_reference|}}}|/||}}}}
,并且得到了相同的结果。

还有其他方法可以实现这一点吗?

谢谢。

mediawiki mediawiki-templates wikitext
1个回答
0
投票

您可以使用

{{#explode:}}

{{Sasines full
<!-- Split nrs_reference by "/" and takes the first fragment -->
|{{#explode:{{{nrs_reference|}}}|/|0}}
<!-- Split nrs_reference by "/" and takes the second fragment -->
|{{#explode:{{{nrs_reference|}}}|/|1}}
}}

您的尝试不起作用,因为

{{#replace:}}
返回值内的管道不被视为
Sasines full
参数的分隔符,而是一个普通的管道字符。

© www.soinside.com 2019 - 2024. All rights reserved.