For faster navigation, this Iframe is preloading the Wikiwand page for 帮助:默认参数.

帮助:默认参数

注意:[MW 1.6+]

在一个模板中,如果a有赋值(包括赋空值),则(({a|b))}等于(({a))},否则等于b。这样避免了因(({a))}没有赋值而出现的问题。

这样(({a))}和b可以是最终结果,也可以作为参数名,参数值,模板名,它们的一部分,等等。

局限[编辑]

若有多个默认部分,仅首个有效,比如(({a|b|c|d))}等价于(({a|b))}。

默认值不能包含表格的“|”。

参数名的表达式可以包含“|”,如果表达式是一个模板或参数。

比如:使用Template:x3,包含(({1))}(({1))}(({1))};Template:t2,包含初((1))中((2))末

  • (({a|b|c|d))}得到b
  • (({a|((x3|b))))}得到bbb
  • (({a|(({b|c))))))得到c
  • (({a|[[b|c]]))}得到c
  • (((({x3|a))|b))}得到b——参数“aaa”未赋值
  • ((((((a|b))}|c))}得到c——参数“b”未赋值
  • (({a|<nowiki>b|c</nowiki>))}得到b|c
    ((t2|(({a|<nowiki>b|c</nowiki>))))}得到初-b|c-中((2))末

倒数技术[编辑]

倒数技术可给出给定的倒数的数字参数值。倒数技术可不用使用模板实现。

倒数第一:(({4|(({3|(({2|(({1|*)))))))))))).

倒数第二(参数“ifu”被赋值为空)

((((((if(({4|u))}|3))}|
 ((((((if(({3|u))}|2))}|
  ((((((if(({2|u))}|1))}|
   ((((((if(({1|u))}|0))}|*] //此行无用,仅出于完整性考虑。可用“*”替代。
  ))}
 ))}
))}

即把“4”、“3”、“2”、“1”一次替换为D4、D3、D2、D1,且Dx=[if[x|u]|x-1]。这样,就可以得到倒数第x+1的参数。 使用Template:lastbut0(讨论 - 链入页面 - 编辑)和Template:lastbut1(讨论 - 链入页面 - 编辑):

  • ((lastbut0))得到no input;
  • ((lastbut0|a))得到a;
  • ((lastbut0|a|b|c|d|e|f|g|h|i|j))得到j;
  • ((lastbut1|ifu=))得到no input;
  • ((lastbut1|ifu=|a))得到no input;
  • ((lastbut1|ifu=|a|b))得到a;
  • ((lastbut1|ifu=|a|b|c|d|e|f|g|h|i|j))得到i;

服务器效率[编辑]

默认参数对服务器来说比多层模板嵌套效率更高。

{{bottomLinkPreText}} {{bottomLinkText}}
帮助:默认参数
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?