"ഫലകം:If empty/doc" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം
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| |
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>{{ |
:<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>{{ |
:<code><nowiki>{{if empty| {{{logo|}}} | {{{image|}}} | default.svg }}</nowiki></code> |
||
'''Note!''' The parameters to {{tlf| |
'''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| |
<tr><td>{{tlc|if empty}} <td>{{if empty}} <td>Returns an empty string. |
||
<tr><td>{{tlc| |
<tr><td>{{tlc|if empty|one}} <td>{{if empty|one}} <td>Returns the first parameter that is defined and not empty. |
||
<tr><td>{{tlc| |
<tr><td>{{tlc|if empty|one|two}} <td>{{if empty|one|two}} <td> |
||
<tr><td>{{tlc| |
<tr><td>{{tlc|if empty|one|two|three|four}} <td>{{if empty|one|two|three|four}} <td> |
||
<tr><td>{{tlc| |
<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| |
<tr><td>{{tlc|if empty||two|three|four}} <td>{{if empty||two|three|four}} <td> |
||
<tr><td>{{tlc| |
<tr><td>{{tlc|if empty||two||four}} <td>{{if empty||two||four}} <td> |
||
<tr><td><code><nowiki>{{ |
<tr><td><code><nowiki>{{if empty|||||||||nine}}</nowiki></code> <td>{{if empty|||||||||nine}} <td> |
||
<tr><td><code><nowiki>{{ |
<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| |
<tr><td>{{tlc|if empty|}} <td>{{if empty|}} <td>The only parameter is empty or undefined, so returns an empty string. |
||
<tr><td>{{tlc| |
<tr><td>{{tlc|if empty||||}} <td>{{if empty||||}} <td>Returns an empty string. |
||
<tr><td><code><nowiki>{{ |
<tr><td><code><nowiki>{{if empty|{{{1|}}}|{{{2|}}}|three}}</nowiki></code> <td>{{if empty|{{{1|}}}|{{{2|}}}|three}} <td> |
||
<tr><td><code><nowiki>{{ |
<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>{{ |
<tr><td><code><nowiki>{{if empty|{{{logo|}}}|two}}</nowiki></code> <td>{{if empty|{{{logo|}}}|two}} <td> |
||
<tr><td><code><nowiki>{{ |
<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>{{ |
<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>{{ |
<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 a documentation subpage for ഫലകം:If empty. It may contain usage information, categories and other content that is not part of the original ഫലകം page. |
This template is used on 36,20,000+ pages, or roughly 693% of all pages. To avoid major disruption and server load, any changes should be tested in the template's /sandbox or /testcases subpages, or in your own user subpage. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
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
Code | Result | Comment |
---|---|---|
{{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.