Help:Displaying information

Queries in Semantic MediaWiki return lists of pages. The default result simply lists their page titles. Any additional information to fetch from each page, such as a page's property values or categories, it is defined by the printout statements.

There are different kinds of printout statements, but all of them can be recognized by the question mark ? that they start with in the query. The important difference between printout statements and query descriptions is that the former do not restrict the result set in any way, even if some printout has no values for a given page, an empty field will be printed, but the page is still part of the result.

Note, all the printout statements below are used within queries.

Printing property values
The most common form of printout statements are property printouts that display all the values assigned to a certain property. These are written simply as a question mark followed by the property name, e.g.

?Has population

This prints all the values for the «population» property of the query results.

It is possible to change the label for a printout:

?Has population = Number of inhabitants

This still prints the values for the «population» property, but with the modified label.

As mentioned above, some properties may not be defined on some pages, e.g. if something does not have any population. Property conditions with wildcards can be used to ensure that all elements in a query result have some value for a given property, if this is desired.

Printing categories
There are two ways to print category information: either SMW prints all categories assigned to some page, or SMW checks for one particular category. The first case is achieved by the printout

?Category

where «Category» is the name of the Category namespace in the local language. This printout will show all categories that are directly used on a result page. The other option is to ask for one particular category, such as

?Category:Actor

The result then will contain a column «Actor» that contains X for all pages that directly belong to that category, and is empty otherwise. Again, one can change the label using equality:

?Category:Actor = A

will merely display an «A» as the header of the result column which might be more sensible given that the entries in that column are very short. It is also possible to change the way in which this kind of category queries are formatted, as described below.

The main result column
All queries by default display the main list of result pages in the first column. In some cases, it can be useful to move that to another position. This is not relevant for Special:Ask, but can be quite useful in inline queries. A special printout statement is available for this purpose:

?

This single question mark addresses the «unlabelled result column» that shows the main result list. As before, different labels can be assigned with the equality symbol, e.g.

? = Results

If you like to hide or omit the main result column, you may use the parameter  (see also here).

Display format
Many printout statements can be further customized by giving a printout format which can be given after a property name, separated by the symbol #. The available formats depend on the type of the printout and involved property.

Plain (unformatted) printouts
A general format that is supported by most types of printouts is the plain format (or empty format), available since SMW 1.4.3. Printouts with this format will avoid all forms of beautification or linking in their presentation, and return a plain value instead. This is particularly useful when results are further processed in templates or parser functions. To select the plain output format, a hyphen ("-") or simply nothing is used as a printout string, as in the following examples:

?Has population # - ?Has capital #

Both printouts select the plain format. For numerical properties like the population number, the plain format is a simple number string without commas to separate digits. For properties of type page, the plain output is simply the name of the page without any link.

It is also possible to get the result of the first result column as a plain (unformatted) printout:

?=#

Prior to it was also possible to use   which is no longer supported.

Note that plain printouts for properties with units (see below) will still include the unit as part of the result (A value that is a (physical) dimension consists of a number multiplied by a quantity (unit), so leaving out the unit would change the value). For this reason, two special printout formats have been added (available since 1.5.1):

Given a value of "12,345.6 km": ?My value # - gives "12345.6 km" (the number and the unit) ?My value # -n gives "12345.6" (just the number) ?My value # -u gives "km" (just the unit)

Custom units
For properties that support units, queries can thus determine which unit should be used for the output. To print the height in cm, e.g., one would use the following:

?Has height # cm

this assumes that the property height is aware of the unit «cm».

The unit can be omitted all together, returning just a number, or queried on its own, returning just the unit :

?Has height #-n ?Has height #-u

Display precision
For properties that support units, queries can thus determine which display precision should be used for the output. This is possible since Semantic MediaWiki 2.4.0.CiteRef::gh:smw:1335

|?Has number #-p2

Display precision can also be combined with Custom units, e.g.

|?Has number #-n-p2

See the page on  for further examples.

Date
For properties of type "Date", four additional output formats are available:
 * 1) " " is available to obtain results in a technical format that conforms to the ISO 8601 standard.
 * 2) " " is available to use the MediaWiki's i18n methods for time and date formatting for the date range, typically between 1901-12-14 and 2038-01-19.
 * 3) " " is available to use predefined value formats for time and date formatting for the date range, typically between 1901-12-14 and 2038-01-19.
 * 4) " " is available to use freely definable value formats for time and date formatting for the date range, typically between 1901-12-14 and 2038-01-19.
 * Example:
 * Use  for day,   for month,   for the yearCiteRef::mediawiki:parserfunctions:time
 * Syntax:
 * Result:
 * 31-11-2019
 * 31-11-2019

Boolean
For properties of type "Boolean", one additional output format is available:
 * 1) " " is available to use localised language strings.

Also the localised language string of a certain language may be enforced:



URL
For properties of type URL, one additional output format is available:
 * " " is available that escapes the URL string will to prevent MediaWiki from making a link of it. Thus it appears as a plain string in HTML and Wikitext alike.

Other
Other datatypes may have different printout formats. See the types documentation for details.

For printouts of the form ?Category:Actor, the display format can be used to modify what SMW will display for cases where a page is (or is not) in the category. The following is an example:

?Category:Actor # an actor, not an actor

This will show the text «an actor» for all pages that are actors, and the text «not an actor» otherwise. This can, for example, also be used in combination with small images to display icons for certain categories.

Customizing printout labels
It is also possible to style labels using basic HTML and CSS. Example: ?Has population= Number of inhabitants

A custom class as shown in the above example needs to be defined in the wiki's CSS, too.

Besides, one can also add tooltips to the labels by using the parser function. Example: ?Has population=Number of inhabitants

Property chains and paths
The property chains and paths allows selecting pages with help of subqueries and property chain conditions. This is possible since Semantic MediaWiki 2.5.0.CiteRef::gh:smw:1824

Inverse properties in printout statements
Starting with Semantic MediaWiki 2.4.0 it is possible to use inverse properties in printout statements.CiteRef::gh:smw:1270. The sandbox wiki provides an example demonstrating this.CiteRef::sb:smw:1270

Full-text search highlighting
Starting with Semantic MediaWiki 2.5.0 it is possible to highlight the search strings within the search results.CiteRef::gh:smw:2253.