Jump to content

Template:If empty/doc

From Wikipedia

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]

Template:Aligned table

See also

[edit source]