Template:If empty
Jump to navigation
Jump to search
This template uses Lua. Its code can be found under Module:If empty. |
This template takes any number of parameters and returns the first found to be defined and non-empty. If none is found, nothing is returned. By writing {{if empty|a|b|c}}
instead of {{#if:a|a|{{#if:b|b|c}}}}
, expression a and b do not have to be repeated and evaluated twice.
This is designed to be used inside other templates. It provides a fallback order, similar to a try/catch based programming style.
Typical usage is like this:
{{If empty |{{{logo|}}} |{{{image|}}} |{{{picture|}}} |default.svg}}
- — Return {{{logo|}}} if it has a value; else {{{image|}}} if it has a value; else {{{picture|}}} 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".
See Wikipedia:Template:If empty for complete documentation.
The above documentation is transcluded from Template:If empty/doc. (edit | history)
Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages.
Add categories and interwikis to the /doc subpage. Subpages of this template.
Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages.
Add categories and interwikis to the /doc subpage. Subpages of this template.