跳至內容

模板: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}}}