Template:If empty/doc

Description
This template is used inside other templates. It takes any number of parameters and returns the first found to be defined and non-empty. If none is found, nothing is returned. Typical usage is like this:


 * ("Return if it has a value; else  if it has a value; else  if it has a value; else return "default.svg".")
 * ("Return if it has a value; else  if it has a value; else  if it has a value; else return "default.svg".")

This returns the first of the parameters logo, image and picture that is defined and non-empty, otherwise "default.svg".

Preamble
The MediaWiki parameter default function doesn't return the default value for empty parameters. That is,  does not return "default.svg" if the template was called like this:.

The usual workaround for a single parameter is:
 * ("If has a value, return it, else return "default.svg".")
 * ("If has a value, return it, else return "default.svg".")

But this becomes complex when several parameters are to be checked:
 * ("If has a value, return it; else if  has a value, return that; else if  has a value, return that; else return "default.svg".")
 * ("If has a value, return it; else if  has a value, return that; else if  has a value, return that; else return "default.svg".")

In these cases, if empty produces the simpler syntax (as above):

Piping
Parameters used with if empty must be piped – i.e. include the vertical bar (pipe) symbol ("|") as a trailing character – so that empty or undefined parameters aren't treated as text and returned incorrectly. Hence, for example,,   and   rather than  ,   and   in the above examples.

Credits
This template's code and documentation were taken from the English Wikipedia.