Help:Template format - userparam parameter

From semantic-mediawiki.org
Jump to: navigation, search
Template formatHelp:Template format - userparam parameter
Table of Contents

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

Usage

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}}}. 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.

Example 1 - default value via the {{{userparam}}} variable

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 km²
84.556 sqmi
of Amsterdam. 43,765 people squeeze into the 60 km²
23.166 sqmi
of Belleville. 3,520,061 people squeeze into the 891.85 km²
344.343 sqmi
of Berlin. ... 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

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 km²
84.556 sqmi
of Amsterdam. 43,765 people have their home into the 60 km²
23.166 sqmi
of Belleville. 3,520,061 people have their home into the 891.85 km²
344.343 sqmi
of Berlin. ... further results

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

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

The example "The template format 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. ^  Semantic MediaWiki: GitHub commit gh:smw:cbf79f5
  3. a b  Semantic MediaWiki: GitHub commit gh:smw:a832dc0