سانچہ:اگرخالی
| اس سانچہ میں صرف منتظمین کی طرف سے ترمیم کی جا سکتی ہے کیونکہ اسے ابشاری محفوظ شدگی میں شامل کیا گیا ہے۔ |
| یہ سانچہ in system messages۔ اس میں کی جانے والی تبدیلیاں فوری طور پر ویکیپیڈیا کے صارف انٹرفیس پر اثر انداز ہو سکتی ہیں۔ بڑے پیمانے پر خلل سے بچنے کے لیے، کسی بھی تبدیلی کا تجربہ پہلے سانچے کے /تختہ مشق یا /ثابتات کے ذیلی صفحات پر کریں، یا اپنے ذاتی صارف صفحہ کے ذیلی صفحہ پر انھیں آزمائیں۔ آزمودہ تبدیلیوں کو ایک ہی ترمیم کے ذریعے اس صفحے پر شامل کیا جا سکتا ہے۔ نیز تبدیلیوں کے نفاذ سے قبل تبادلۂ خیال صفحہ پر گفتگو بھی فرما لیں تو مناسب ہوگا۔ |
| اس سانچے میں حسب ذیل لوا ماڈیول زیر استعمال ہے: |
This template is used inside other templates. It takes any number of parameters and returns the first found to be defined and non-empty. If none is found, nothing is returned. By writing {{اگرخالی|a|b|c}} instead of {{#if:a|a|{{#if:b|b|c}}}}, expression a and b do not have to be repeated and evaluated twice. The template provides a fallback order, similar to a try catch based "It is easier to ask for forgiveness than permission" (EAFP) programming style.
Typical usage is like this:
{{اگرخالی|{{{logo|}}} |{{{image|}}} |{{{picture|}}} |default.svg}}- — Return {{{logo|}}} if it has a value; else {{{image|}}} if it has a value; else {{{picture|}}} if it has a value; else return "default.svg".
This returns the first of the parameters logo, image and picture that is defined and non-empty, otherwise "default.svg".
Rationale
[ترمیم]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 for a single parameter is:
{{#if:{{{logo|}}} |{{{logo}}} |default.svg}}- — If {{{logo}}} has a value, return it, else return "default.svg".
But this becomes complex when several parameters are to be checked:
{{#if:{{{logo|}}} |{{{logo}}} |{{#if:{{{image|}}} |{{{image}}} |{{#if:{{{picture|}}} |{{{picture}}} |default.svg}} }} }}- — 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".
In these cases, {{if empty}} produces the simpler syntax (as above):
{{اگرخالی|{{{logo|}}} |{{{image|}}} |{{{picture|}}} |default.svg}}
Piping
[ترمیم]Parameters used with {{if empty}} must be piped – i.e. include the vertical bar (pipe) symbol ("سانچہ:Thin space|سانچہ:Thin space") as a trailing character – so that empty or undefined parameters aren't treated as text and returned incorrectly. Hence, for example, {{{logo|}}}, {{{image|}}} and {{{picture|}}} rather than {{{logo}}}, {{{image}}} and {{{picture}}} in the above examples.
Examples
[ترمیم]| Code | Result | |
{{if empty}} | Returns an empty string. | |
{{if empty|one}} | one | Returns the first parameter that is defined and not empty. |
{{if empty|one|two|three|four}} | one | |
{{اگرخالی||two}} | two | The first parameter is empty/undefined, so is passed over. |
{{اگرخالی||two||four}} | two | |
{{اگرخالی||||||||||ten}} | ten | Unlike in previous versions, this template is no longer limited by 9 parameters. |
{{if empty|}} | The only parameter is empty or undefined, so the template returns an empty string. | |
{{if empty|||||}} | Returns an empty string. | |
{{اگرخالی|{{{1|}}}|{{{2|}}}|three}} | three | Neither 1 nor 2 are defined, so "three" is returned. |
{{اگرخالی|{{{1}}}|{{{2}}}|three}} | {{{1}}} | No pipe-characters following the names of the first two parameters ("1" and "2"), so the first is returned as text ("{{{1}}}"). |
{{اگرخالی|{{{logo|}}}|two}} | two | |
{{اگرخالی|{{{logo}}}|two}} | {{{logo}}} | No pipe-character following the parameter name "logo", so the text "{{{logo}}}" is returned. |
{{اگرخالی|p=q}} | The template identifies the parameters it receives as parameters 1 to 9, not using names such as "p", etc. |
| اوپر دی گئی دستاویز صفحہ سانچہ:اگرخالی/دستاویز سے شامل کی گئی ہے۔ (ترمیم | تاریخچہ) صارفین سانچہ کے تختہ مشق (تخلیق | آئینہ) اور ثابتات (تخلیق) میں تجربات کرسکتے ہیں۔ براہ کرم /دستاویز کے ذیلی صفحہ پر زمرہ جات شامل فرمائیں۔ اس سانچہ کے ذیلی صفحات۔ |