模板:If then show
跳转到导航
跳转到搜索
File:Test Template Info-Icon - Version (2).svg 模板文档[查看] [编辑] [历史] [清除缓存]
| File:Edit-copy green with red question mark.svg | 此模板的文档不存在、不全面或不能详细描述其功能及/或其代码中的参数。请帮助扩充并改进其文档。 |
此模板检查首个未命名参数是否为空字符串,非空字符串则返回它,否则返回第二个未命名参数。
通常用于首个参数是调用Lua模块的{{#invoke: }},模块可能返回一个值或者不返回值。这样只使用{{#invoke: }}一次,有助于简化信息框等位置的编写。
可选的第三个和第四个未命名参数为返回第一个参数时提供前缀和后缀。如此方便构建更复杂的模板,且仍只需调用一次Lua模块。
用法[编辑]
- Module:Wikibase第27行Lua错误:attempt to index field 'wikibase' (a nil value) (Q151973)的Module:Wikibase第27行Lua错误:attempt to index field 'wikibase' (a nil value) (P26)
{{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q151973|fwd=ALL|osd=no}}|未婚}}→ Module:WikidataIB第761行Lua错误:attempt to index field 'wikibase' (a nil value)
- Module:Wikibase第27行Lua错误:attempt to index field 'wikibase' (a nil value) (Q905)的Module:Wikibase第27行Lua错误:attempt to index field 'wikibase' (a nil value) (P26)
{{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q905|fwd=ALL|osd=no}}|未婚}}→ Module:WikidataIB第761行Lua错误:attempt to index field 'wikibase' (a nil value)
前缀和后缀[编辑]
有微格式的信息框字段[编辑]
如果调用的维基数据不为空,可以将信息框中的值以微格式封装:
{{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>. - 如果没有指定本地参数,会尝试从维基数据获取Module:Wikibase第27行Lua错误:attempt to index field 'wikibase' (a nil value) (P19)的值。
- 如果有值,例如“纽约”,该代码返回
<span class="birthplace">纽约</span>。 - 如果维基数据中没有对应的值,这段代码什么也不做。
表格[编辑]
可以支持仅维基数据存在对应内容时显示为表格的一行。
- Module:Wikibase第27行Lua错误:attempt to index field 'wikibase' (a nil value) (Q151973)的Module:Wikibase第27行Lua错误:attempt to index field 'wikibase' (a nil value) (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>}} |}- →
| 标签 | 值 |
|---|---|
| Module:WikidataIB第532行Lua错误:attempt to index field 'wikibase' (a nil value) | Module:WikidataIB第761行Lua错误:attempt to index field 'wikibase' (a nil value) |
- Module:Wikibase第27行Lua错误:attempt to index field 'wikibase' (a nil value) (Q905)的Module:Wikibase第27行Lua错误:attempt to index field 'wikibase' (a nil value) (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>}} |}- →
| 标签 | 值 |
|---|---|
| Module:WikidataIB第532行Lua错误:attempt to index field 'wikibase' (a nil value) | Module:WikidataIB第761行Lua错误:attempt to index field 'wikibase' (a nil value) |
参见[编辑]
{{#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.