<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.limswiki.org/index.php?action=history&amp;feed=atom&amp;title=Template%3AIf_empty%2Fdoc</id>
	<title>Template:If empty/doc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.limswiki.org/index.php?action=history&amp;feed=atom&amp;title=Template%3AIf_empty%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://www.limswiki.org/index.php?title=Template:If_empty/doc&amp;action=history"/>
	<updated>2026-04-05T02:52:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.36.1</generator>
	<entry>
		<id>https://www.limswiki.org/index.php?title=Template:If_empty/doc&amp;diff=27870&amp;oldid=prev</id>
		<title>Shawndouglas: Created as needed.</title>
		<link rel="alternate" type="text/html" href="https://www.limswiki.org/index.php?title=Template:If_empty/doc&amp;diff=27870&amp;oldid=prev"/>
		<updated>2016-09-23T21:25:38Z</updated>

		<summary type="html">&lt;p&gt;Created as needed.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Documentation subpage}}&lt;br /&gt;
{{Lua|Module:If empty}}&lt;br /&gt;
&amp;lt;!----PLEASE ADD CATEGORIES WHERE INDICATED AT THE BOTTOM OF THIS PAGE----&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the {{tl|If empty}} template.&lt;br /&gt;
&lt;br /&gt;
*''Update 2014 Dec 23'': This template used to only take 9 parameters. This limit has been removed.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{If empty |{{{logo|}}} |{{{image|}}} |{{{picture|}}} |default.svg}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
: &amp;lt;nowiki&amp;gt;(&amp;quot;Return {{{logo|}}} if it has a value; else {{{image|}}} if it has a value; else {{{picture|}}} if it has a value; else return &amp;quot;default.svg&amp;quot;.&amp;quot;)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
This returns the first of the parameters ''logo'', ''image'' and ''picture'' that is defined and non-empty, otherwise &amp;quot;default.svg&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Rationale===&lt;br /&gt;
The MediaWiki parameter default function doesn't return the default value for empty parameters. That is, &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{{logo|default.svg}}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; does not return &amp;quot;default.svg&amp;quot; if the template was called like this: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{template|logo=}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The usual workaround for a single parameter is:&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#if:{{{logo|}}} |{{{logo}}} |default.svg}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
: &amp;lt;nowiki&amp;gt;(&amp;quot;If {{{logo}}} has a value, return it, else return &amp;quot;default.svg&amp;quot;.&amp;quot;)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But this becomes complex when several parameters are to be checked:&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#if:{{{logo|}}} |{{{logo}}} |{{#if:{{{image|}}} |{{{image}}} |{{#if:{{{picture|}}} |{{{picture}}} |default.svg}} }} }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
: &amp;lt;nowiki&amp;gt;(&amp;quot;If {{{logo}}} has a value, return it; else if {{{image}}} has a value, return that; else if {{{picture}}} has a value, return that; else return &amp;quot;default.svg&amp;quot;.&amp;quot;)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
In these cases, {{tlf|if empty}} produces the simpler syntax (as above):&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{if empty |{{{logo|}}} |{{{image|}}} |{{{picture|}}} |default.svg}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Piping====&lt;br /&gt;
Parameters used with {{tlf|if empty}} must be piped&amp;amp;nbsp;– i.e. include the vertical bar (pipe) symbol {{nowrap|(&amp;quot;{{thin space}}&amp;amp;#124;{{thin space}}&amp;quot;)}} as a trailing character&amp;amp;nbsp;– so that empty or undefined parameters aren't treated as text and returned incorrectly. Hence, for example, &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{{logo|}}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{{image|}}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{{picture|}}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; rather than {{param|logo}}, {{param|image}} and {{param|picture}} in the above examples.&lt;br /&gt;
&lt;br /&gt;
===Examples===&lt;br /&gt;
{{Aligned table |class=wikitable&lt;br /&gt;
 |cols=3 |col1style=padding-right:1.0em; |col2style=padding-left:0.5em;padding-right:1.0em; |col3style=padding-left:0.5em;&lt;br /&gt;
 |row1style=background:whitesmoke;padding-left:0.5em;font-weight:bold;&lt;br /&gt;
 | Code | Result |&lt;br /&gt;
 | {{tc|if empty}} | {{if empty}} | Returns an empty string.&lt;br /&gt;
 | {{tc|if empty|one}} | {{if empty|one}} | Returns the first parameter that is defined and not empty.&lt;br /&gt;
 | {{tc|if empty|one|two}} | {{if empty|one|two}} | &lt;br /&gt;
 | {{tc|if empty|one|two|three|four}} | {{if empty|one|two|three|four}} | &lt;br /&gt;
 | {{tc|if empty||two}} | {{if empty||two}} | The first parameter is empty/undefined, so is passed over.&lt;br /&gt;
 | {{tc|if empty||two|three|four}} | {{if empty||two|three|four}} | &lt;br /&gt;
 | {{tc|if empty||two||four}} | {{if empty||two||four}} | &lt;br /&gt;
 | &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{if empty||||||||||ten}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; | {{if empty||||||||||ten}} | Unlike in previous versions, this template is no longer limited by 9 parameters.&lt;br /&gt;
 | {{tc|if empty|}} | {{if empty|}} | The only parameter is empty or undefined, so returns an empty string.&lt;br /&gt;
 | {{tc|if empty||||}} | {{if empty||||}} | Returns an empty string.&lt;br /&gt;
 | &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{if empty|{{{1|}}}|{{{2|}}}|three}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; | {{if empty|{{{1|}}}|{{{2|}}}|three}} | &lt;br /&gt;
 | &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{if empty|{{{1}}}|{{{2}}}|three}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; | {{if empty|{{{1}}}|{{{2}}}|three}} | No pipe-characters following the names of the first two parameters (&amp;quot;1&amp;quot; and &amp;quot;2&amp;quot;), so the first of these returned as text (&amp;quot;{{{1}}}&amp;quot;).&lt;br /&gt;
 | &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{if empty|{{{logo|}}}|two}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; | {{if empty|{{{logo|}}}|two}} | &lt;br /&gt;
 | &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{if empty|{{{logo}}}|two}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; | {{if empty|{{{logo}}}|two}} | No pipe-character following the parameter name &amp;quot;logo&amp;quot;, so the text &amp;quot;{{{logo}}}&amp;quot; returned.&lt;br /&gt;
 | &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{if empty|p=q}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; | {{if empty|p=q}} | The template identifies the parameters it receives as parameters 1 to 9, not using names such as &amp;quot;p&amp;quot;, etc.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
===See also===&lt;br /&gt;
* {{tl|if all}}&lt;br /&gt;
* {{tl|if either}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;includeonly&amp;gt;{{#ifeq:{{SUBPAGENAME}}|sandbox |&lt;br /&gt;
| &amp;lt;!-- ADD CATEGORIES BELOW THIS LINE, PLEASE: --&amp;gt;&lt;br /&gt;
[[Category:If-then-else templates]]&lt;br /&gt;
}}&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>Shawndouglas</name></author>
	</entry>
</feed>