跳转到内容

Template:Conditional template call with newline/doc

维基百科,自由的百科全书

该模版在条件{{{1}}}下调用模版{{{2}}}并使用参数{{{3}}},且在结尾添加一个换行符。

该模板用于避免两次写出条件:一次用于模板调用,一次用于换行。Template:If可用于保留换行符。

用法

[编辑]

Sample 1

[编辑]

Example using Template:2x, which simply repeats its argument twice, so {{2x|Pizza}} produces PizzaPizza. One can combine this with {{Conditional template call with newline}} in the following code

{{#tag:pre|{{Conditional template call with newline|1|2x|Pizza}}{{Conditional template call with newline|0|2x|Bora}}{{Conditional template call with newline|1|2x|Bang}}}}

which produces
PizzaPizza
BangBang

Notice how BoraBora is suppressed, and there is a newline between PizzaPizza and BangBang.

Sample 2

[编辑]

Example using {{Table row Dutch municipality}}

{| class="wikitable sortable"
!Municipality!!Population
{{Conditional template call with newline|1|Table row Dutch municipality|Delft}}{{Conditional template call with newline|0|Table row Dutch municipality|Hoorn}}{{Conditional template call with newline|1|Table row Dutch municipality|Rotterdam}}|}

gives

Municipality Population

Template:Table row Dutch municipality Template:Table row Dutch municipality

The template is typically called by another table row template, which has as parameter {{{1}}} the identification of the potential item (in this template: {{{3}}}), and some parameter {{{2}}} related to the condition. That template provides the condition in terms of {{{1}}} and {{{2}}}.

Sample 3

[编辑]

Sample usage with full substitution of the template to create a newline in wikitext.

1. Create a sample template : "Template:testnewline"

ABC{{<includeonly>subst:</includeonly>Conditional template call with newline|{{<includeonly>subst:</includeonly>#ifeq:{{{align|}}}|{{{align}}}|1|0}}|void|1|substctc=subst:|subst=subst:}}
DEF

2. When called empty ({{subst:testnewline}}), it generates the following wikitext:

ABC
DEF

3. When called as {{subst:testnewline|align=somevalue}}, it generates the following wikitext (note the newline):

ABC

DEF

参数

[编辑]

必选参数

[编辑]
1
第一个未命名参数,用于判断条件。其中1代表真(True),而0代表假(False)。如果条件为真,那么第二个模板将被调用,并在结尾添加一个换行符。可直接输入0或1。
示例:{{#ifeq:{{{align|}}}|{{{align}}}|1|0}}。当一个模板被调用,且使用align为任意值的参数时条件为真:而align未包含时条件为假。
2
第二个未命名参数,为需要调用模板的名称。
可使用Template:!代替“!”,Template:Void代替“void”。

可选参数

[编辑]
3
3rd unnamed parameter, value to be assigned to {{{1}}} when calling template {{{2}}}
substctc
for substitution of some parser functions and auxiliary templates called inside the template, use the value "subst:"; recommended when the template is substituted; note that in that case any parser functions or templates in the condition have to be substituted too.
subst
for substitution of template {{{2}}}, use the value "subst:"
p1n
name of an additional parameter used by template {{{2}}}
p1v
value to be assigned to {{{p1n}}} when calling template {{{2}}}