Help:List format

From semantic-mediawiki.org

Jump to: navigation, search

The result formats list, ol and ul are used to format query results as lists, bulleted lists, or numbered lists. The format list is the default way of formatting query results for all queries that have no additional printout statements.

Contents

Examples

Examples for plain lists

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

Result: Berlin, Hannover, Munich, and Stuttgart

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 (Population 3,391,407, Size in km² 891.69 km²891,690,000 m²
89,169 ha
344.283 miles²
1.74817e-6 earths
), Hannover (Population 515,772), Munich (Population 1,259,677, Size in km² 310.46 km²310,460,000 m²
31,046 ha
119.869 miles²
6.0866e-7 earths
), and Stuttgart (Population 595,452, Size in km² 207.458 km²207,458,047.638 m²
20,745.805 ha
80.1 miles²
4.06724e-7 earths
)

The headers can be hiden by giving them empty labels:

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

Result: Berlin (3,391,407, 891.69 km²891,690,000 m²
89,169 ha
344.283 miles²
1.74817e-6 earths
), Hannover (515,772), Munich (1,259,677, 310.46 km²310,460,000 m²
31,046 ha
119.869 miles²
6.0866e-7 earths
), and Stuttgart (595,452, 207.458 km²207,458,047.638 m²
20,745.805 ha
80.1 miles²
4.06724e-7 earths
)

The same effect is achieved by headers=hide. Another separator than «,» and the final «and» can be used if specified by sep:

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

Result: Berlin and Hannover and Munich and Stuttgart

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

Examples for bulleted and numbered lists

Ordered lists are created with ol:

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

Result:

  1. Berlin (Population 3,391,407, Size in km² 891.69 km²891,690,000 m²
    89,169 ha
    344.283 miles²
    1.74817e-6 earths
    )
  2. Hannover (Population 515,772)
  3. Munich (Population 1,259,677, Size in km² 310.46 km²310,460,000 m²
    31,046 ha
    119.869 miles²
    6.0866e-7 earths
    )
  4. Stuttgart (Population 595,452, Size in km² 207.458 km²207,458,047.638 m²
    20,745.805 ha
    80.1 miles²
    4.06724e-7 earths
    )

Unordered lists are created with ul:

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

Result:


Parameters

The list formats introduce the following additional parameters:

  • 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:Inline queries.

Remarks

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 tempalte 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».

This documentation page applies to all SMW versions from 0.7 to the most current version.
     

Help:List format en 0.7

Personal tools