قالب:Ifempty/شرح
هذه صفحة توثيق قالب:Ifempty الفرعية، لشرح القالب وتصنيفه، وهي لا تدخل في استخدامه. |
قالب {{Ifempty}} إذا كان فارغ.
This template is used inside other templates. It takes up to four parameters and returns the first one that has any content. That is, the first one that is defined (not null) and not empty. Typical usage is like this:
{{Ifempty| {{{logo|}}} | {{{image|}}} | default.svg}}
خلفية
عدل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: {{قا|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.
أمثلة
عدل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|four}} | four | |
{{ifempty|five}} | five | Only handles up to four 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}}} | Fails. Note the lack of "|" in the first two parameters. |
{{Ifempty|{{{logo|}}}|two}} | two | |
{{Ifempty|{{{logo}}}|two}} | {{{logo}}} | Fails. Note the lack of "|" in the first parameter. |
طالع أيضاً
عدل- {{بك}} – Helps handling image width parameters in templates.
- مساعدة:Parameter default – You probably don't need to know this anymore if you use this template.