"ഫലകം:If empty/doc" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം
Content deleted Content added
imported>Sardanaphalus updates following move |
imported>Sardanaphalus shortcut, heading, formatting, some rephrasing, sandbox non-categorization, Aligned table |
||
വരി 1:
{{Documentation subpage}}
{{Template shortcut|ifempty}}
{{
<!--
This is the {{tl|if empty}} template.
This template is used inside other templates. It takes up to nine parameters (unnamed parameters 1-9)
: <code><nowiki>{{if empty
:
This returns the first of the parameters ''logo'' and ''image'' that is defined and non-empty, otherwise "default.svg".
===
The MediaWiki parameter default function doesn't return the default value for empty parameters. That is, <code><nowiki>{{{logo|default.svg}}}</nowiki></code> does not return "default.svg" if the template was called like this: <code><nowiki>{{template|logo=}}</nowiki></code>.
The usual workaround
: <code><nowiki>{{#if:{{{logo|}}} |
: {{95%|<nowiki>("If {{{logo}}} has a value, return it, else return "default.svg".")</nowiki>}}
But this becomes complex when you want to check several parameters:▼
▲:<code><nowiki>{{if empty| {{{logo|}}} | {{{image|}}} | default.svg }}</nowiki></code>
=== Examples ===▼
<table class="wikitable">▼
<tr><td>{{tlc|if empty}} <td>{{if empty}} <td>Returns an empty string.▼
<tr><td>{{tlc|if empty|one}} <td>{{if empty|one}} <td>Returns the first parameter that is defined and not empty.▼
<tr><td>{{tlc|if empty|one|two}} <td>{{if empty|one|two}} <td>▼
<tr><td>{{tlc|if empty|one|two|three|four}} <td>{{if empty|one|two|three|four}} <td>▼
<tr><td>{{tlc|if empty||two}} <td>{{if empty||two}} <td>The first parameter was empty or undefined, so uses the next parameter.▼
<tr><td>{{tlc|if empty||two|three|four}} <td>{{if empty||two|three|four}} <td>▼
<tr><td>{{tlc|if empty||two||four}} <td>{{if empty||two||four}} <td>▼
<tr><td><code><nowiki>{{if empty|||||||||nine}}</nowiki></code> <td>{{if empty|||||||||nine}} <td>▼
<tr><td><code><nowiki>{{if empty||||||||||ten}}</nowiki></code> <td>{{if empty||||||||||ten}} <td>Only handles up to nine parameters, so returns an empty string.▼
<tr><td>{{tlc|if empty|}} <td>{{if empty|}} <td>The only parameter is empty or undefined, so returns an empty string.▼
<tr><td>{{tlc|if empty||||}} <td>{{if empty||||}} <td>Returns an empty string.▼
<tr><td><code><nowiki>{{if empty|{{{1|}}}|{{{2|}}}|three}}</nowiki></code> <td>{{if empty|{{{1|}}}|{{{2|}}}|three}} <td>▼
<tr><td><code><nowiki>{{if empty|{{{1}}}|{{{2}}}|three}}</nowiki></code> <td>{{if empty|{{{1}}}|{{{2}}}|three}} <td>Returns the text "{{{1}}}", because it is a non-empty string. Note the lack of "|" in the first two parameters.▼
<tr><td><code><nowiki>{{if empty|{{{logo|}}}|two}}</nowiki></code> <td>{{if empty|{{{logo|}}}|two}} <td>▼
: {{95%|<nowiki>("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 "default.svg".)</nowiki>}}
<tr><td><code><nowiki>{{if empty|2=x}}</nowiki></code> <td>{{if empty|2=x}} <td>Whether parameter 1 is undefined or empty does not matter.▼
In these cases, {{tlf|if empty}} produces the simpler syntax above:
<tr><td><code><nowiki>{{if empty|p=q}}</nowiki></code> <td>{{if empty|p=q}} <td>The template checks its parameters 1-9, not other ones. ▼
▲: <code><nowiki>{{
===
Parameters used with {{tlf|if empty}} must be [[Pipe (Unix)|pipe]]d – i.e. include the [[Vertical bar|vertical bar (pipe) symbol]] {{nowrap|("{{thinsp}}{{{thinsp}}")}} as a trailing character – so that empty or undefined parameters aren't treated as text and returned incorrectly. Hence, for example, {{code|{{{logo{}}}}}, {{code|{{{image{}}}}} and {{code|{{{picture{}}}}} rather than {{param|logo}}, {{param|image}} and {{param|picture}} in the above examples.
* {{tl|If all}}▼
* {{tl|If either}}▼
|cols=3 |col1style=padding-right:1.0em; |col2style=padding-left:0.5em;padding-right:1.0em; |col3style=padding-left:0.5em;
|row1style=background:whitesmoke;padding-left:0.5em;font-weight:bold;
| Code | Result |
▲
▲
▲
▲
▲
▲
▲
▲
| <code><nowiki>{{if empty|{{{logo}}}|two}}</nowiki></code> | {{if empty|{{{logo}}}|two}} | No pipe-character following the parameter name "logo", so the text "{{{logo}}}" returned.
▲
▲
}}
===See also===
* {{tl|px}} – Helps handling image width parameters in templates.▼
* [[Help:Parameter default]]
<includeonly>
{{#ifeq:{{SUBPAGENAME}}|sandbox | |
<!--
[[Category:If-then-else templates
}}
</includeonly>
|