Archive:List format 0.7 - 1.6.2

From semantic-mediawiki.org


This documentation page applies to all SMW versions from 0.7 to 1.6.2.
      Other languages: de

Help:List format en 0.7 1.6.2


List format 0.7 - 1.6.2
Comma-separated list, with additional outputs shown in parentheses
Further Information
Provided by: Semantic MediaWiki
Added: 0.7
Removed: still supported
Requirements: none
Format name: list
Enabled? Indicates whether the result format is enabled by default upon installation of the respective extension. yes
Authors: Markus Krötzsch
Categories: misc
Table of Contents

The result format list is used to format query results as comma-separated lists. The format list is the default way of formatting query results for all queries that have no additional printout statements. Similar results formats are ol and ul.

Parameters[edit]

Parameter Aliases Type Default Description
propsep - text , The separator between the properties of a result entry
valuesep - text , The separator between the values for a property of a result
template - text empty The name of a template with which to display the printouts
named args namedargs yes/no no Name the arguments passed to the template
userparam - text empty A value passed into each template call, if a template is used
class - text empty An additional CSS class to set for the list
introtemplate - text empty The name of a template to display before the query results, if there are any
outrotemplate - text empty The name of a template to display after the query results, if there are any
sep - text , The separator between results

This format introduces the following additional parameters:

  • columns: the number of columns into which to split up results (default is 1)
  • sep: the text to be used to separate items
  • template: the name of a template for template-based formatting

The use of templates for formatting is explained in Help:Result templates.

Examples[edit]

{{#ask: [[Category:City]] [[located in::Germany]] }}

Result: Berlin, Cologne, Frankfurt, Munich, Stuttgart, Würzburg

If more printouts are given, then the format must be requested explicitly:

{{#ask: [[Category:City]] [[located in::Germany]] 
| ?population
| ?area#km² = Size in km²
| format=list
}}

Result: Berlin (PopulationThe number of inhabitants of some geographical place.: 3,520,061, Size in km²: 891.85 km²344.34 sqmi <br />), Cologne (PopulationThe number of inhabitants of some geographical place.: 1,080,394, Size in km²: 405.02 km²156.38 sqmi <br />), Frankfurt (PopulationThe number of inhabitants of some geographical place.: 679,664, Size in km²: 248.31 km²95.87 sqmi <br />), Munich (PopulationThe number of inhabitants of some geographical place.: 1,353,186, Size in km²: 310.43 km²119.86 sqmi <br />), Stuttgart (PopulationThe number of inhabitants of some geographical place.: 606,588, Size in km²: 207.35 km²80.06 sqmi <br />), Würzburg (PopulationThe number of inhabitants of some geographical place.: 126,635, Size in km²: 87.63 km²33.83 sqmi <br />)

The headers can be hidden by giving them empty labels:

{{#ask: [[Category:City]] [[located in::Germany]] 
| ?population =
| ?area#km² = 
| format=list
}}

Result: Berlin (3,520,061, 891.85 km²344.34 sqmi <br />), Cologne (1,080,394, 405.02 km²156.38 sqmi <br />), Frankfurt (679,664, 248.31 km²95.87 sqmi <br />), Munich (1,353,186, 310.43 km²119.86 sqmi <br />), Stuttgart (606,588, 207.35 km²80.06 sqmi <br />), Würzburg (126,635, 87.63 km²33.83 sqmi <br />)

The same effect is achieved by headers=hide.

Another separator than «,» e.g. «and» can be used if specified by sep:

{{#ask: [[Category:City]] [[located in::Germany]] | sep =  _and_ }}

Result: Berlin_and_Cologne_and_Frankfurt_and_Munich_and_Stuttgart_and_Würzburg

The underscores here are used to create spaces that are not removed by MediaWiki when reading the parameter.

Remarks[edit]

Using the format list with templates has the advantage of having the right amount of separators (e.g. «,») between results. For example, one can have a template that formats email lists that can be copied and pasted into an email client, where each entry has the form

Name of person <email@example.com>

It makes sense to set sep=,_ to have a list that uses commas for all separators instead of having the last one being an «and».