Working with the #set "template" parameter

Jump to: navigation, search
"template" parameter to #set
This page describes the "template" parameter to the "#set" parser function.
Table of Contents

Semantic MediaWiki 2.2.0Released on 9 May 2015 and compatible with MW 1.19.0 - 1.24.x. 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 29 October 2015 and compatible with MW 1.19.0 - 1.25.x. 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.



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

 |Has text=fc00:123:8000::/%6

Example - multiple value display

As of Semantic MediaWiki 2.3.0Released on 29 October 2015 and compatible with MW 1.19.0 - 1.25.x., 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

 |Has text=fc00:123:8000::/%6;2001:db8::1428:57ab;2001:db8:0:8d3:0:8a2e:70:7344
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 ",":

fc00:123:8000::/%6, 2001:db8::1428:57ab, 2001:db8:0:8d3:0:8a2e:70:7344, 


  1. ^  Semantic MediaWiki: GitHub issue gh:smw:756
  2. ^  Semantic MediaWiki: GitHub issue gh:smw:1048
  3. ^  Semantic MediaWiki: GitHub pull request gh:smw:1066
  4. ^  Semantic MediaWiki: GitHub pull request gh:smw:1107