Help:Template format - userparam parameter

From semantic-mediawiki.org
< Archive:Template format(Redirected from Help:Template format - userparam parameter)
Template formatHelp:Template format - userparam parameter
Table of Contents
See the help page on the userparam parameter to result format "Plainlist"Outputs results in a comma separated list, with additional outputs shown in parentheses. The output does not provide class attributes to HTML elements (default for queries without printout statements). for current documentation.

This help page provides information and examples about the userparam parameter and the respective {{{userparam}}} ({{{#userparam}}} for SMW 3.0+) variable to result format "Template"Uses a specified template to format and display the results allowing to add user parameters to the query.

Usage[edit]

It is possible to add a (single) extra parameter to the query. To do this you add userparam=<value> to the query. In the template used to format the results of the query, the value given after userparam= will be available as the value for the variable called {{{userparam}}} ({{{#userparam}}} for SMW 3.0+). This allows for extra re-usability for the template. You can create a single template that can be called from different queries with different results, based on the parameter. Since Semantic MediaWiki 1.9.2Released on 18 April 2014 and compatible with MW 1.19.0 - 1.22.x., this feature not only apply to the template but also to the introtemplate and the outrotemplate.1

Semantic MediaWiki 1.9.2Released on 18 April 2014 and compatible with MW 1.19.0 - 1.22.x. brought even further improvements by introducing the parameters {{{smw-resultquerycondition|}}}2, {{{smw-resultquerylimit|}}}3 and {{{smw-resultqueryoffset|}}}3 that make the respective information available to the template on which it was added via inheritance. Semantic MediaWiki 3.0.0 renamed these parameters to {{{#querycondition|}}}, {{{#querylimit|}}} and {{{#resultoffset|}}} respectively.4

Example 1 - default value via the {{{userparam}}} variable[edit]

This example shows how you can set a default value for the userparam parameter by specifying it via the {{{userparam}}} variable in the respective template with {{{userparam|default value}}}:

{{#ask:
 [[Category:City]]
 [[Area::+]]
 [[Population::+]] 
 |?Population=Inhabitants
 |?Area#km²=Size in km²
 |format=template
 |template=Query output demo
 |limit=3
}}
Result

783,364 people squeeze into the 219.00 km²84.56 sqmi <br /> of Amsterdam. 3,520,061 people squeeze into the 891.85 km²344.34 sqmi <br /> of Berlin. 1,080,394 people squeeze into the 405.02 km²156.38 sqmi <br /> of Cologne. ... further results NoteNote:  The value "squeeze" was used in the output since this was specified as the default via template by adding {{{userparam|squeeze}}} to it. There was no value specified in the query via |userparam= to override it.

Example 2 - individual value via the userparam parameter[edit]

This example shows how you can set an individual value for the userparam parameter which will override the default value specified via the {{{userparam}}} variable in the respective template with {{{userparam|default value}}}:

{{#ask:
 [[Category:City]]
 [[Area::+]]
 [[Population::+]] 
 |?Population=Inhabitants
 |?Area#km²=Size in km²
 |format=template
 |template=Query output demo
 |limit=3
 |userparam=''have their home''
}}
Result

783,364 people have their home into the 219.00 km²84.56 sqmi <br /> of Amsterdam. 3,520,061 people have their home into the 891.85 km²344.34 sqmi <br /> of Berlin. 1,080,394 people have their home into the 405.02 km²156.38 sqmi <br /> of Cologne. ... further results

NoteNote:  The value "have their home" was used in the output since this was specified in the query via the |userparam= parameter to override the the default set via template which contains {{{userparam|squeeze}}} ({{{#userparam|squeeze}}} in v3.0+).

Example 3 - inherit query conditions, limit and offset to the "outrotemplate"[edit]

The example "Templates used to create a tabular output combined with math formats" shows how to use {{{smw-resultquerycondition|}}}, {{{smw-resultquerylimit|}}} and {{{smw-resultqueryoffset|}}} parameter.

References

  1. ^  Semantic MediaWiki: GitHub pull request gh:smw:217
  2. ^  
    GitHub commit gh:smw:cbf79f5
  3. a b  
    GitHub commit gh:smw:a832dc0
  4. ^  Semantic MediaWiki: GitHub pull request gh:smw:3130