Template:If empty/doc
| This is a documentation subpage for Template:If empty It contains usage information, categories and other content that is not part of the original template page. |
| This template uses Lua: |
| This template is used on 55,000+ pages and changes may be widely noticed. Test changes in the template's /sandbox or /testcases subpages, or in your own user subpage. Consider discussing changes on the talk page before implementing them. |
This be the {{If empty}} template.
- Update 2014 Dec 23: This template dey take only 9 parameters before. This limit no dey again.
This template dey used inside other templates. E fit take any number of parameters and e go return the first one wey dey defined and no be empty. If e no find any, nothing go return. Normal usage be like this:
{{If empty |{{{logo|}}} |{{{image|}}} |{{{picture|}}} |default.svg}}- ("Return {{{logo|}}} if e get value; if not, return {{{image|}}} if e get value; if not, return {{{picture|}}} if e get value; if not, return "default.svg".")
This go return the first parameter from logo, image and picture wey dey defined and no be empty. If not, e go return "default.svg".
Reason
[edit source]The MediaWiki parameter default function no dey return the default value for empty parameters. Meaning say, {{{logo|default.svg}}} no go return "default.svg" if the template call be like this: {{template|logo=}}.
The normal way to solve one parameter be:
{{#if:{{{logo|}}} |{{{logo}}} |default.svg}}- ("If {{{logo}}} get value, return am; if not, return "default.svg".")
But this one go make things complicated when plenty parameters need checking:
{{#if:{{{logo|}}} |{{{logo}}} |{{#if:{{{image|}}} |{{{image}}} |{{#if:{{{picture|}}} |{{{picture}}} |default.svg}} }} }}- ("If {{{logo}}} get value, return am; if not, check {{{image}}}; if {{{image}}} get value, return am; if not, check {{{picture}}}; if {{{picture}}} get value, return am; if not, return "default.svg".")
For this kind cases, {{if empty}} give simpler way to write am:
{{if empty |{{{logo|}}} |{{{image|}}} |{{{picture|}}} |default.svg}}
Piping
[edit source]Parameters wey dey use with {{if empty}} need pipe – meaning say dem need include the vertical bar (pipe) symbol ("Template:Thinsp|Template:Thinsp") at the end – so empty or undefined parameters no go show as text by mistake. So, for example, use {{{logo|}}}, {{{image|}}} and {{{picture|}}} instead of Template:Param, Template:Param and Template:Param like the examples above.
Examples
[edit source]See also
[edit source]- {{if all}}
- {{if either}}
- Help:Parameter default