Help:Parser functions in templates/zh

当在模板参数中使用解析器函数时，可以使用一个管道符号（|）来提供一个默认值，会在没有参数填写时被使用. 在 #if 解析器函数中使用时，来自未定义参数的未扩展文本将解析为真，可能造成意想不到的结果.




 * 例 A:


 * 结果:




 * 列 B:


 * Result :

The second usage (, sample B) with present empty default is often the desired way to handle situations where a parameter exists, but is comprised only of empty space.

Testing and passing undefined parameters
To distinguish a possibly empty parameter from an unspecified one, compare it to itself using  and different defaults. What the defaults are does not matter as long as they are different, so they are typically chosen to be short. The following all work equivalently:



In rare cases, a template behaves differently when a parameter is unspecified compared to when it is specified but empty. When this template is used by a wrapper template (which uses the same set of named parameters), one way to ensure undefined parameters remain undefined is as follows (the technique also works with numbered parameters):





receives a defined normal_parameter in all cases. When normal_parameter is defined but empty and when it is undefined,  receives an empty normal_parameter.

By contrast, the  receives a defined sensitive_parameter only when it is indeed defined; when sensitive_parameter is undefined, the   changes the parameter name to sensitive_parameterNULL. The suffixed parameter name must be meaningless to the  for this to work properly.



參見

 * Extension:Loops#forargs