"ഫലകം:If empty/doc" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം
No edit summary |
(ചെ.) Migrating 15 interwiki links, now provided by Wikidata on d:Q5902486 |
||
വരി 60: | വരി 60: | ||
<!-- ADD CATEGORIES AND INTERWIKIS BELOW THIS LINE --> |
<!-- ADD CATEGORIES AND INTERWIKIS BELOW THIS LINE --> |
||
[[Category:If-then-else templates|{{PAGENAME}}]] |
[[Category:If-then-else templates|{{PAGENAME}}]] |
||
[[as:সাঁচ:Ifempty]] |
|||
[[be:Шаблон:Ifempty]] |
|||
[[cy:Nodyn:Ifempty]] |
|||
[[en:Template:Ifempty]] |
|||
[[ja:Template:Ifempty]] |
|||
[[ka:თარგი:Ifempty]] |
|||
[[km:ទំព័រគំរូ:Ifempty]] |
|||
[[ko:틀:ifempty]] |
|||
[[lv:Veidne:Ifempty]] |
|||
[[ne:ढाँचा:Ifempty]] |
|||
[[or:ଛାଞ୍ଚ:Ifempty]] |
|||
[[pt:Predefinição:Ifempty]] |
|||
[[ru:Шаблон:Ifempty]] |
|||
[[te:మూస:Ifempty]] |
|||
[[tr:Şablon:Boşsa]] |
|||
</includeonly> |
</includeonly> |
09:34, 28 മാർച്ച് 2013-നു നിലവിലുണ്ടായിരുന്ന രൂപം
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 692% 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 {{ifempty}} 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:
{{ifempty| {{{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:
{{ifempty| {{{logo|}}} | {{{image|}}} | default.svg }}
Note! The parameters to {{ifempty}} must use the pipe "|", like this: {{{logo|}}}
. Or else {{ifempty}} will be fed and return the string "{{{logo}}}
" if logo was not defined.
Examples
Code | Result | Comment |
---|---|---|
{{ifempty}} | Returns an empty string. | |
{{ifempty|one}} | one | Returns the first parameter that is defined and not empty. |
{{ifempty|one|two}} | one | |
{{ifempty|one|two|three|four}} | one | |
{{ifempty|two}} | two | The first parameter was empty or undefined, so uses the next parameter. |
{{ifempty|two|three|four}} | two | |
{{ifempty|two|four}} | two | |
{{ifempty|||||||||nine}} | nine | |
{{ifempty||||||||||ten}} | ten | Only handles up to nine parameters, so returns an empty string. |
{{ifempty}} | The only parameter is empty or undefined, so returns an empty string. | |
{{ifempty}} | Returns an empty string. | |
{{ifempty|{{{1|}}}|{{{2|}}}|three}} | three | |
{{ifempty|{{{1}}}|{{{2}}}|three}} | {{{1}}} | Returns the text "{{{1}}}", because it is a non-empty string. Note the lack of "|" in the first two parameters. |
{{ifempty|{{{logo|}}}|two}} | two | |
{{ifempty|{{{logo}}}|two}} | {{{logo}}} | Returns the text "{{{logo}}}", because it is a non-empty string. Note the lack of "|" in the first parameter. |
{{ifempty|2=x}} | Whether parameter 1 is undefined or empty does not matter. | |
{{ifempty|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.