For faster navigation, this Iframe is preloading the Wikiwand page for 模板:If then show.

模板: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.
{{bottomLinkPreText}} {{bottomLinkText}}
模板:If then show
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?