Difference between revisions of "Template:If then show/doc"

From blackwiki
Jump to navigation Jump to search
imported>RexxS
(documentation)
 
imported>RexxS
(fix association lists)
Line 6: Line 6:
  
 
== Usage ==
 
== Usage ==
 +
 
; {{q|P26}} for {{q|Q151973}}
 
; {{q|P26}} for {{q|Q151973}}
* <code><nowiki>{{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q151973|fwd=ALL|osd=no}}|unmarried}}</nowiki></code> → {{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q151973|fwd=ALL|osd=no}}|unmarried}}
+
: <code><nowiki>{{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q151973|fwd=ALL|osd=no}}|unmarried}}</nowiki></code> → {{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q151973|fwd=ALL|osd=no}}|unmarried}}
  
 
; {{q|P26}} for {{q|Q905}}
 
; {{q|P26}} for {{q|Q905}}
* <code><nowiki>{{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q905|fwd=ALL|osd=no}}|unmarried}}</nowiki></code> → {{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q905|fwd=ALL|osd=no}}|unmarried}}
+
: <code><nowiki>{{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q905|fwd=ALL|osd=no}}|unmarried}}</nowiki></code> → {{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q905|fwd=ALL|osd=no}}|unmarried}}
  
  

Revision as of 11:51, 27 July 2018

This template tests whether the first unnamed parameter is not an empty string and returns it if it does. Otherwise it returns the second unnamed parameter.

This is useful when the first parameter is a {{#invoke: }} of a Lua module that may return a value or nothing. Because it uses the {{#invoke: }} just once, it simplifies the coding of infoboxes, for example.

Usage

Lua error in Module:Wd at line 196: attempt to index field 'wikibase' (a nil value). (P26) for Lua error in Module:Wd at line 196: attempt to index field 'wikibase' (a nil value). (Q151973)
{{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q151973|fwd=ALL|osd=no}}|unmarried}} → unmarried
Lua error in Module:Wd at line 196: attempt to index field 'wikibase' (a nil value). (P26) for Lua error in Module:Wd at line 196: attempt to index field 'wikibase' (a nil value). (Q905)
{{If then show|{{#invoke:WikidataIB|getValue|P26|qid=Q905|fwd=ALL|osd=no}}|unmarried}} → unmarried