Help:Parser functions in templates

When applying Parser Functions to template parameters, a pipe symbol ("|") may be used to provide the empty string as default value, in order to indicate how to handle things if a parameter is or isn't specified.




 * Sample A:


 * Result:




 * Sample B:


 * Result:


 * Comparison

The second usage is often the desired way to handle situations where a parameter exists, but is comprised only of empty space.

One way to test whether a parameter was specified in a template call is thus:

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):

Note that the  receives a specified but empty   in two cases: when   is specified and empty, and when   is unspecified (because the default empty value is then specified by the wrapper template).

By contrast, the  receives a specified   only when it is indeed specified, because the   changes the   parameter name to «   » when   is undefined. Note also that  receives a specified and empty   only when the wrapper template receives a specified and empty. Of course, one must make sure the suffixed  parameter name is meaningless to the   for this to work properly.