Help:Plainlist format – parameter userparam

From semantic-mediawiki.org
< Help:Plainlist format
Plainlist formatHelp:Plainlist format – parameter userparam
Parameter userparam
This help page explains how to pass a custom extra parameter to the template used to display the output of the query.
Keywords

This help page explains the usage of the userparam parameter when using templates with 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). to display the output of your queries.

Since Semantic MediaWiki 1.9.2Released on 18 April 2014 and compatible with MW 1.19.0 - 1.22.x., this parameter does not just apply to the template parameter but also to the introtemplate parmeter and the outrotemplate parameter.1

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 specified to format the results of the query, the value given after userparam= will be available as the value for the variable called {{{#userparam}}}2, prior to Semantic MediaWiki 3.0.0Released on 11 October 2018 and compatible with MW 1.27.0 - 1.31.x. like, e.g. {{{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.

Example - default value[edit]

Syntax
{{#ask:
 [[Category:City]]
 [[Located in::Germany]]
 [[Area::+]]
 [[Population::+]] 
 |?Population
 |?Area
 |format=plainlist
 |template=TableUserparam
}}
Result
  • Berlin − 3,520,061 people on 891.85 km²344.34 sqmi <br />.
  • Cologne − 1,080,394 people on 405.02 km²156.38 sqmi <br />.
  • Frankfurt − 679,664 people on 248.31 km²95.87 sqmi <br />.
  • Munich − 1,353,186 people on 310.43 km²119.86 sqmi <br />.
  • Stuttgart − 606,588 people on 207.35 km²80.06 sqmi <br />.
  • Würzburg − 126,635 people on 87.63 km²33.83 sqmi <br />.

The template used to create this example: TableUserparam.

Note
  • The variable is added to the template like, e.g. {{{#userparam}}}. Prior to Semantic MediaWiki 3.0.0Released on 11 October 2018 and compatible with MW 1.27.0 - 1.31.x. like, e.g. {{{userparam}}}.
  • To provide a default value with the variable if none was specified with the query for the respective printout statement, i.e. userparam=<value> is missing use, e.g. {{{#userparam|sometext}}}.
  • To prevent using a default value with the variable if no value was specified with the query for the respective printout statement, i.e. userparam=<value> is missing use {{{#userparam|}}}.

Example - individual value[edit]

Syntax
{{#ask:
 [[Category:City]]
 [[Located in::Germany]]
 [[Area::+]]
 [[Population::+]] 
 |?Population
 |?Area
 |format=plainlist
 |template=TableUserparam
 |userparam=have their home on a total of
}}
Result
  • Berlin − 3,520,061 people have their home on a total of 891.85 km²344.34 sqmi <br />.
  • Cologne − 1,080,394 people have their home on a total of 405.02 km²156.38 sqmi <br />.
  • Frankfurt − 679,664 people have their home on a total of 248.31 km²95.87 sqmi <br />.
  • Munich − 1,353,186 people have their home on a total of 310.43 km²119.86 sqmi <br />.
  • Stuttgart − 606,588 people have their home on a total of 207.35 km²80.06 sqmi <br />.
  • Würzburg − 126,635 people have their home on a total of 87.63 km²33.83 sqmi <br />.

The template used to create this example: TableUserparam.

Note
  • The default value provided with the variable, e.g. {{{#userparam|sometext}}}, is being overridden by the value specified with userparam=<value>.

See also[edit]

References

  1. ^  Semantic MediaWiki: GitHub pull request gh:smw:217
  2. ^  Semantic MediaWiki: GitHub issue gh:smw:2488