"ഫലകം:If empty/doc" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം

imported>Sardanaphalus
updates following move
imported>Sardanaphalus
shortcut, heading, formatting, some rephrasing, sandbox non-categorization, Aligned table
വരി 1:
{{Documentation subpage}}
{{Template shortcut|ifempty}}
{{highHigh-use| 381,000+ }}
<!-- --PLEASE ADD CATEGORIES ANDWHERE INTERWIKISINDICATED AT THE BOTTOM OF THIS PAGE ---->
 
This is the {{tl|if empty}} template.
 
This template is used inside other templates. It takes up to nine parameters (unnamed parameters 1-9), and returns the first onefound thatto isbe defined and non-empty,. otherwiseIf none is found, nothing is returned. Typical usage is like this:
: <code><nowiki>{{if empty| |{{{logo|}}} | {{{image|}}} |{{{picture|}}} |default.svg }}</nowiki></code>
 
:<code> {{95%|<nowiki>("Return {{{logo|}}} if empty|it has a value, else {{{logoimage|}}} |if it has a value, else {{{imagepicture|}}} |if it has a value, else return "default.svg }}".")</nowiki></code>}}
This returns the first of the parameters ''logo'' and ''image'' that is defined and non-empty, otherwise "default.svg".
 
=== Background Rationale===
 
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 isfor toa dosingle likeparameter thisis:
: <code><nowiki>{{#if:{{{logo|}}} | {{{logo}}} | default.svg }}</nowiki></code>
: {{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:{{{logo|}}}| {{{logo}}} | {{#if:{{{image|}}} | {{{image}}} | default.svg }}}}</nowiki></code>
 
Then it is easier to use this template instead:
 
:<code><nowiki>{{if empty| {{{logo|}}} | {{{image|}}} | default.svg }}</nowiki></code>
 
'''Note!''' The parameters to {{tlf|if empty}} must use the pipe "|", like this: <code><nowiki>{{{logo|}}}</nowiki></code>. Or else {{tlf|if empty}} will be fed and return the string "<code><nowiki>{{{logo}}}</nowiki></code>" if ''logo'' was not defined.
 
=== Examples ===
 
<table class="wikitable">
<tr><th>Code<th>Result<th>Comment
<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.
 
But this becomes complex when youseveral wantparameters are to checkbe several parameterschecked:
<tr><td><code><nowiki>{{if empty|{{{logo|}}}|two}}</nowiki></code> <td>{{if empty|{{{logo|}}}|two}} <td>
<tr><td>: <code><nowiki>{{#if empty|:{{{logo|}}} |two{{{logo}}}</nowiki></code> <td>|{{#if:{{{image|}}} empty|{{{logoimage}}} |two{{#if:{{{picture|}}} <td>Returns the text "|{{{logopicture}}}", because it is a non-empty string|default.svg}} Note the}} lack of "|" in the first parameter.}}</nowiki></code>
: {{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>{{#if: empty |{{{logo|}}}| {{{logo}}} | {{#if:{{{image|}}} | {{{imagepicture|}}} | default.svg }}}}</nowiki></code>
</table>
 
=== See also =Piping====
Parameters used with {{tlf|if empty}} must be [[Pipe (Unix)|pipe]]d&nbsp;– i.e. include the [[Vertical bar|vertical bar (pipe) symbol]] {{nowrap|("{{thinsp}}&#123;{{thinsp}}")}} as a trailing character&nbsp;– so that empty or undefined parameters aren't treated as text and returned incorrectly. Hence, for example, {{code|{{{logo&#123;}}}}}, {{code|{{{image&#123;}}}}} and {{code|{{{picture&#123;}}}}} rather than {{param|logo}}, {{param|image}} and {{param|picture}} in the above examples.
 
=== Examples ===
* {{tl|If all}}
<{{Aligned table |class="wikitable">
* {{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 |
<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 wasis empty or /undefined, so usesis thepassed next parameterover.
<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| handlesEmpty upstring toreturned nineif parameters,maximum soof returnsnine anparameters empty stringexceeded.
<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| theNo textpipe-characters "{{{1}}}",following becausethe itnames isof athe non-emptyfirst string.two Noteparameters the("1" lack ofand "|2"), inso the first twoof parametersthese returned as text ("{{{1}}}").
<tr><td> | <code><nowiki>{{if empty|{{{logo|}}}|two}}</nowiki></code> <td>| {{if empty|{{{logo|}}}|two}} <td>|
| <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.
<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.
<tr><td> | <code><nowiki>{{if empty|p=q}}</nowiki></code> <td>| {{if empty|p=q}} <td>| The template checksidentifies itsthe parameters it receives as parameters 1- to 9, not otherusing ones.names such as "p", etc.
}}
 
===See also===
* {{tl|px}} – Helps handling image width parameters in templates.
* {{tl|Ifif all}}
* [[Help:Parameter default]] – You probably don't need to know this anymore if you use this template.
* {{tl|Ifif either}}
* {{tl|px}} assists Helpsin handling image width parameters in templates.
* [[Help:Parameter default]]
 
<includeonly>
{{#ifeq:{{SUBPAGENAME}}|sandbox | |
<!-- --ADD CATEGORIES AND INTERWIKIS BELOW THIS LINE, PLEASE:---->
[[Category:If-then-else templates|{{PAGENAME}}]]
}}
</includeonly>
"https://ml.wikipedia.org/wiki/ഫലകം:If_empty/doc" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്