Template:If empty/doc

This is the ifempty template.

This template is used inside other templates. It takes up to nine parameters (parameters 1-9), and returns the first one that is defined and non-empty, otherwise nothing. Typical usage is like this:



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

Background
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 is to do like this:

But this becomes complex when you want to check several parameters:



Then it is easier to use this template instead:



Note! The parameters to must use the pipe "|", like this:. Or else will be fed and return the string " " if logo was not defined.

Examples
Only handles up to nine parameters, so returns an empty string. The only parameter is empty or undefined, so returns an empty string. Returns an empty string.

Returns the text "", because it is a non-empty string. Note the lack of "|" in the first two parameters.

Returns the text "", because it is a non-empty string. Note the lack of "|" in the first parameter. Whether parameter 1 is undefined or empty does not matter. The template checks its parameters 1-9, not other ones.