模板:If then show

本頁使用了標題或全文手工轉換
被永久保護的模板
維基百科,自由的百科全書
文件圖示 模板文件[檢視] [編輯] [歷史] [清除快取]

此模板檢查首個未命名參數是否為空字串,非空字串則返回它,否則返回第二個未命名參數。

通常用於首個參數是調用Lua模組的{{#invoke: }},模組可能返回一個值或者不返回值。這樣只使用{{#invoke: }}一次,有助於簡化資訊框等位置的編寫。

可選的第三個和第四個未命名參數為返回第一個參數時提供前綴和後綴。如此方便構建更複雜的模板,且仍只需調用一次Lua模組。

用法

理查德·伯頓 (Q151973)配偶 (P26)
{{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q151973|fwd=ALL|osd=no}}|未婚}}伊利沙伯·泰勒、Sybil Christopher、蘇茜·米勒、伊利沙伯·泰勒、Sally Burton 編輯維基數據
弗朗茨·卡夫卡 (Q905)配偶 (P26)
{{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q905|fwd=ALL|osd=no}}|未婚}} → 未婚

前綴和後綴

有微格式的資訊框字段

如果調用的維基數據不為空,可以將資訊框中的值以微格式封裝:

{{if then show | {{#invoke:WikidataIB | getValue | rank=best |P19 |name=birth_place |qid={{{qid|}}} |suppressfields={{{suppressfields|}}} |fetchwikidata={{{fetchwikidata|}}} |noicon={{{noicon|}}} | {{{birth_place|}}} }} || <span class="birthplace"> | </span>}}
如果條目中指定了本地參數(例如|birth_place=倫敦),該代碼返回<span class="birthplace">伦敦</span>.
如果沒有指定本地參數,會嘗試從維基數據獲取出生地 (P19)的值。
如果有值,例如「紐約」,該代碼返回<span class="birthplace">纽约</span>
如果維基數據中沒有對應的值,這段代碼什麼也不做。

表格

可以支持僅維基數據存在對應內容時顯示為表格的一行。

理查德·伯頓 (Q151973)配偶 (P26)
{| class="wikitable"
|-
! scope="col" style="width:15em;" | 标签
! scope="col" style="width:36em;" | 值
{{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q151973|fwd=ALL|osd=no}}||<tr><th>{{#invoke:WikidataIB|getLabel|P26|qid=Q151973}}</th><td>|</td></tr>}}
|}
標籤
配偶伊利沙伯·泰勒、Sybil Christopher、蘇茜·米勒、伊利沙伯·泰勒、Sally Burton 編輯維基數據
弗朗茨·卡夫卡 (Q905)配偶 (P26)
{| class="wikitable"
|-
! scope="col" style="width:15em;" | 标签
! scope="col" style="width:36em;" | 值
{{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q905|fwd=ALL|osd=no}}||<tr><th>{{#invoke:WikidataIB|getLabel|P26|qid=Q905}}</th><td>|</td></tr>}}
|}
標籤

參見

{{#invoke:Wikidata Infobox|ifThenShow}}
Lua-based alternative that does basically the same thing
Template:Ifnoteq then show
測試第一個未命名參數是否等於第二個未命名參數,如果相等則返回第三個未命名參數,否則返回第一個未命名參數。通常用於首個參數以{{#invoke:調用一個Lua模組,返回的值排除指定的例外。
Template:If then wikilink
tests whether the first unnamed parameter is not an empty string and if it isn't, it returns the parameter formatted as piped wiki-link using an optional namespace prefix.
Template:Formatter link
將一個外部標識符作為|code=參數,格式化URL作為|url=參數,構造一個指向外部資源的連結。
Template:Emptyor
tests a piece of text to ascertain whether it's effectively empty or contains some text. If the unnamed parameter consists only of html tags, punctuation (e.g. Wiki-markup) and whitespace, then Emptyor returns nothing; otherwise it returns the parameter unchanged. Wrapper for p.emptyor function.