Template:Ifempty
このテンプレートは他のテンプレート内で使用します。引数のうち、最初に中身の存在する引数を表示します。
| このテンプレートは958,000以上のページで使われています。 余計な混乱やサーバーへの負荷を避けるために、どんな変更でも最初はテンプレートのサンドボックス・サブページ、テストケース・サブページもしくはあなた自身の利用者スペースのページで試すべきです。そうすれば、試した変更を1度の編集でこのテンプレートに加えることができます。しかし、最初にあなたの提案した変更を、この項目のノートで議論するようにお願いします。 |
| Luaモジュールを使用しています: |
このテンプレートは他のテンプレート内で使用します。引数のうち、最初に中身の存在する引数を表示します。
使用例
{{ifempty| {{{logo|}}} | {{{image|}}} | default.svg }}
この場合、
- logo が指定されていれば、logo の値を
- logo が指定されておらず image が指定されていれば、image の値を
- logo も image も指定されていなければ、default.svg を
表示します。
解説
MediaWikiにおいてテンプレート変数を処理する際、空の呼び出しをされた変数は、デフォルト値を返しません。例えば、Template:Templateに{{{logo|default.svg}}}という処理があり、これを{{template|logo=}}と呼び出した場合、"default.svg"ではなく、空の値が返ってきます。
この問題を回避するためには、条件文を用いて以下のように記述します。
{{ #if: {{{logo|}}} | {{{logo}}} | default.svg }}
別の変数が組み合わさった場合は、以下のように記述します。
{{ #if: {{{logo|}}} | {{{logo}}} | {{ #if: {{{image|}}} | {{{image}}} | default.svg }} }}
これを本テンプレートを用いて、以下のように記述できます。
{{ ifempty | {{{logo|}}} | {{{image|}}} | default.svg }}
TemplateData
引数のうち、最初に中身の存在する引数を表示するテンプレート。
| パラメーター | 説明 | 型 | 状態 | |
|---|---|---|---|---|
| 1 | 1 | 第1引数 | 不明 | 必須 |
| 2 | 2 | 第2引数 | 不明 | 必須 |
| 3 | 3 | 第3引数 | 不明 | 省略可能 |
| 4 | 4 | 第4引数 | 不明 | 省略可能 |
| 5 | 5 | 第5引数 | 不明 | 省略可能 |
| 6 | 6 | 第6引数 | 不明 | 省略可能 |
| 7 | 7 | 第7引数 | 不明 | 省略可能 |
| 8 | 8 | 第8引数 | 不明 | 省略可能 |
| 9 | 9 | 第9引数 | 不明 | 省略可能 |
| 10 | 10 | 第10引数。第11以降も現実的な範囲で使用できます。 | 不明 | 省略可能 |
関連項目
- {{cond}}
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.