Working with the #set "template" parameter

From Linux Web Expert

Revision as of 11:40, 22 November 2020 by >Kghbln (chg)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

"template" parameter to #setProperty "Has name" (as page type) with input value ""template" parameter to #set" contains invalid characters or is incomplete and therefore can cause unexpected results during a query or annotation process.
This page describes the "template" parameter to the "#set" parser function.
Keywords
Table of Contents

Semantic MediaWiki 2.2.0Released on an unknown date unknown versions of MediaWiki added support of the |template=... parameter to the #set parser function. The parameter also provides the following fixed named arguments allowing for customized links or queries:1

  • {{{property}}} – holds the name of the property used
  • {{{value}}} – holds the value assigned to the property used
  • {{{#}}} – holds the number of the property value assignments (annotations) made
  • {{{last-element}}} – determines whether the given property value assignment is the last one emitted with the template (Semantic MediaWiki 2.3.0Released on an unknown date unknown versions of MediaWiki and higher)

The template is applied to the entire #set, i.e. to "property1" and to "property2", etc. Thus the template "TemplateUsedForEntireSetCall" only needs to be added to the line setting the first property e.g. "propery1". A second template added to e.g. "propery2", etc. will be ignored. If one would like to use a second query one will have to add a second #set parser function to the respective page.

Syntax

{{#set:
 |property1=value1;value2;value3|+sep=;|template=TemplateUsedForEntireSetCall
 |property2=value1,value2,value3|+sep=,
 ...
}}

Example - "set query"

See this page for an example

Example - restricted characters

Where the in-text annotation using the :: syntax, e.g. [[PropertyName::PropertyValue]] does not work due to interference with the parser (value contains square brackets, wiki-links, extra colons), a template e.g. BySetTemplateSimpleValueOutput added to a #set call can create an annotation and display the value at the same time.23

{{#set:
 |Has text=fc00:123:8000::/%6
 |template=BySetTemplateSimpleValueOutput
}}
Result
fc00:123:8000::/%6

Example - multiple value display

As of Semantic MediaWiki 2.3.0Released on an unknown date unknown versions of MediaWiki, a {{{last-element}}} parameter is automatically added to the template allowing to determine if the given value is the last element (= last value) returned via the template (list or query) or not e.g. BySetTemplateSimpleValueOutputMultiple. If the property value is the "last element" (= "last value") returned the parameter's value is "1" and if it is not "0" will be returned.4

{{#set:
 |Has text=fc00:123:8000::/%6;2001:db8::1428:57ab;2001:db8:0:8d3:0:8a2e:70:7344
 |+sep=;
 |template=BySetTemplateSimpleValueOutputMultiple
}}
Result
fc00:123:8000::/%6, 2001:db8::1428:57ab, 2001:db8:0:8d3:0:8a2e:70:7344

Without the {{{last-element}}} parameter as shown in template BySetTemplateSimpleValueOutputMultipleWithout there would be no way to determine the last element and apply different formatting. Note the trailing comma ",":

Result
fc00:123:8000::/%6, 2001:db8::1428:57ab, 2001:db8:0:8d3:0:8a2e:70:7344, 
#scite could not render a citation text for reference "gh:smw:756" because type "issue" was not assigned to a template.
#scite could not render a citation text for reference "gh:smw:1048" because type "issue" was not assigned to a template.
#scite could not render a citation text for reference "gh:smw:1066" because type "pullrequest" was not assigned to a template.
#scite could not render a citation text for reference "gh:smw:1107" because type "pullrequest" was not assigned to a template.

References

  1. ^ gh:smw:756 
  2. ^ gh:smw:1048 
  3. ^ gh:smw:1066 
  4. ^ gh:smw:1107