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

വിക്കിപീഡിയ, ഒരു സ്വതന്ത്ര വിജ്ഞാനകോശം.
Content deleted Content added
update, {{high-use| 381,000+ }}
imported>Sardanaphalus
updates following move
വരി 3: വരി 3:
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->


This is the {{tl|ifempty}} template.
This is the {{tl|if empty}} template.


This template is used inside other templates. It takes up to nine parameters (parameters 1-9), and returns the first one that is defined and non-empty, otherwise nothing. Typical usage is like this:
This template is used inside other templates. It takes up to nine parameters (parameters 1-9), and returns the first one that is defined and non-empty, otherwise nothing. Typical usage is like this:


:<code><nowiki>{{ifempty| {{{logo|}}} | {{{image|}}} | default.svg }}</nowiki></code>
:<code><nowiki>{{if empty| {{{logo|}}} | {{{image|}}} | default.svg }}</nowiki></code>
This returns the first of the parameters ''logo'' and ''image'' that is defined and non-empty, otherwise "default.svg".
This returns the first of the parameters ''logo'' and ''image'' that is defined and non-empty, otherwise "default.svg".


വരി 23: വരി 23:
Then it is easier to use this template instead:
Then it is easier to use this template instead:


:<code><nowiki>{{ifempty| {{{logo|}}} | {{{image|}}} | default.svg }}</nowiki></code>
:<code><nowiki>{{if empty| {{{logo|}}} | {{{image|}}} | default.svg }}</nowiki></code>


'''Note!''' The parameters to {{tlf|ifempty}} must use the pipe "|", like this: <code><nowiki>{{{logo|}}}</nowiki></code>. Or else {{tlf|ifempty}} will be fed and return the string "<code><nowiki>{{{logo}}}</nowiki></code>" if ''logo'' was not defined.
'''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 ===
=== Examples ===
വരി 31: വരി 31:
<table class="wikitable">
<table class="wikitable">
<tr><th>Code<th>Result<th>Comment
<tr><th>Code<th>Result<th>Comment
<tr><td>{{tlc|ifempty}} <td>{{ifempty}} <td>Returns an empty string.
<tr><td>{{tlc|if empty}} <td>{{if empty}} <td>Returns an empty string.
<tr><td>{{tlc|ifempty|one}} <td>{{ifempty|one}} <td>Returns the first parameter that is defined and not empty.
<tr><td>{{tlc|if empty|one}} <td>{{if empty|one}} <td>Returns the first parameter that is defined and not empty.
<tr><td>{{tlc|ifempty|one|two}} <td>{{ifempty|one|two}} <td>
<tr><td>{{tlc|if empty|one|two}} <td>{{if empty|one|two}} <td>
<tr><td>{{tlc|ifempty|one|two|three|four}} <td>{{ifempty|one|two|three|four}} <td>
<tr><td>{{tlc|if empty|one|two|three|four}} <td>{{if empty|one|two|three|four}} <td>
<tr><td>{{tlc|ifempty||two}} <td>{{ifempty||two}} <td>The first parameter was empty or undefined, so uses the next parameter.
<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|ifempty||two|three|four}} <td>{{ifempty||two|three|four}} <td>
<tr><td>{{tlc|if empty||two|three|four}} <td>{{if empty||two|three|four}} <td>
<tr><td>{{tlc|ifempty||two||four}} <td>{{ifempty||two||four}} <td>
<tr><td>{{tlc|if empty||two||four}} <td>{{if empty||two||four}} <td>
<tr><td><code><nowiki>{{ifempty|||||||||nine}}</nowiki></code> <td>{{ifempty|||||||||nine}} <td>
<tr><td><code><nowiki>{{if empty|||||||||nine}}</nowiki></code> <td>{{if empty|||||||||nine}} <td>
<tr><td><code><nowiki>{{ifempty||||||||||ten}}</nowiki></code> <td>{{ifempty||||||||||ten}} <td>Only handles up to nine parameters, so returns an empty string.
<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|ifempty|}} <td>{{ifempty|}} <td>The only parameter is empty or undefined, 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|ifempty||||}} <td>{{ifempty||||}} <td>Returns an empty string.
<tr><td>{{tlc|if empty||||}} <td>{{if empty||||}} <td>Returns an empty string.


<tr><td><code><nowiki>{{ifempty|{{{1|}}}|{{{2|}}}|three}}</nowiki></code> <td>{{ifempty|{{{1|}}}|{{{2|}}}|three}} <td>
<tr><td><code><nowiki>{{if empty|{{{1|}}}|{{{2|}}}|three}}</nowiki></code> <td>{{if empty|{{{1|}}}|{{{2|}}}|three}} <td>
<tr><td><code><nowiki>{{ifempty|{{{1}}}|{{{2}}}|three}}</nowiki></code> <td>{{ifempty|{{{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|{{{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>{{ifempty|{{{logo|}}}|two}}</nowiki></code> <td>{{ifempty|{{{logo|}}}|two}} <td>
<tr><td><code><nowiki>{{if empty|{{{logo|}}}|two}}</nowiki></code> <td>{{if empty|{{{logo|}}}|two}} <td>
<tr><td><code><nowiki>{{ifempty|{{{logo}}}|two}}</nowiki></code> <td>{{ifempty|{{{logo}}}|two}} <td>Returns the text "{{{logo}}}", because it is a non-empty string. Note the lack of "|" in the first parameter.
<tr><td><code><nowiki>{{if empty|{{{logo}}}|two}}</nowiki></code> <td>{{if empty|{{{logo}}}|two}} <td>Returns the text "{{{logo}}}", because it is a non-empty string. Note the lack of "|" in the first parameter.
<tr><td><code><nowiki>{{ifempty|2=x}}</nowiki></code> <td>{{ifempty|2=x}} <td>Whether parameter 1 is undefined or empty does not matter.
<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>{{ifempty|p=q}}</nowiki></code> <td>{{ifempty|p=q}} <td>The template checks its parameters 1-9, not other ones.
<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.
</table>
</table>



00:41, 11 ജൂലൈ 2014-നു നിലവിലുണ്ടായിരുന്ന രൂപം

This is the {{if empty}} template.

This template is used inside other templates. It takes up to nine parameters (parameters 1-9), and returns the first one that is defined and non-empty, otherwise nothing. Typical usage is like this:

{{if empty| {{{logo|}}} | {{{image|}}} | default.svg }}

This returns the first of the parameters logo and image that is defined and non-empty, otherwise "default.svg".

Background

The MediaWiki parameter default function doesn't return the default value for empty parameters. That is, {{{logo|default.svg}}} does not return "default.svg" if the template was called like this: {{template|logo=}}.

The usual workaround is to do like this:

{{#if:{{{logo|}}}| {{{logo}}} | default.svg }}

But this becomes complex when you want to check several parameters:

{{#if:{{{logo|}}}| {{{logo}}} | {{#if:{{{image|}}} | {{{image}}} | default.svg }}}}

Then it is easier to use this template instead:

{{if empty| {{{logo|}}} | {{{image|}}} | default.svg }}

Note! The parameters to {{if empty}} must use the pipe "|", like this: {{{logo|}}}. Or else {{if empty}} will be fed and return the string "{{{logo}}}" if logo was not defined.

Examples

CodeResultComment
{{if empty}} Returns an empty string.
{{if empty|one}} one Returns the first parameter that is defined and not empty.
{{if empty|one|two}} one
{{if empty|one|two|three|four}} one
{{if empty|two}} two The first parameter was empty or undefined, so uses the next parameter.
{{if empty|two|three|four}} two
{{if empty|two|four}} two
{{if empty|||||||||nine}} nine
{{if empty||||||||||ten}} ten Only handles up to nine parameters, so returns an empty string.
{{if empty}} The only parameter is empty or undefined, so returns an empty string.
{{if empty}} Returns an empty string.
{{if empty|{{{1|}}}|{{{2|}}}|three}} three
{{if empty|{{{1}}}|{{{2}}}|three}} {{{1}}} Returns the text "{{{1}}}", because it is a non-empty string. Note the lack of "|" in the first two parameters.
{{if empty|{{{logo|}}}|two}} two
{{if empty|{{{logo}}}|two}} {{{logo}}} Returns the text "{{{logo}}}", because it is a non-empty string. Note the lack of "|" in the first parameter.
{{if empty|2=x}} Whether parameter 1 is undefined or empty does not matter.
{{if empty|p=q}} The template checks its parameters 1-9, not other ones.

See also

  • {{px}} – Helps handling image width parameters in templates.
  • Help:Parameter default – You probably don't need to know this anymore if you use this template.


"https://ml.wikipedia.org/w/index.php?title=ഫലകം:If_empty/doc&oldid=2124620" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്