Help:Datatype "Boolean"

Jump to: navigation, search
Holds boolean (true/false) values
Further Information
Provided by: Semantic MediaWiki
Added in version: 1.0
Removed in version: still in use
Datatype ID:
Table of Contents

The datatype Boolean is for attributes that can only have two possible values, called truth value. You can enter "true" or "false", also 1/0, yes/no, t/f, and y/n. Other languages may provide language-specific options.

To allow two arbitrary strings, or more than two possible values (such as no - maybe - probably - yes) use Help:Type String with Property:Allows value to restrict the possible values. In many circumstances it may also be more appropriate to use a category instead of a Boolean.

Displaying Boolean values in inline queries

By default, Boolean values will display true and false in queries. This can be changed by specifying a format string to control what is displayed for the true and false values of a property. Consider, e.g., a Boolean property successful in a wiki about projects, that describes whether or not a certain project was a success. Displaying all projects with their success status could then be achieved as follows:

{{#ask: [[Category:Project]]
| ?successful#success,failure

where success and failure are displayed in a result column labelled "successful". Note that this column may have empty fields, for projects where the success or failure was not determined yet. This is a difference to categories, which can either be true or unset, but not explicitly set to false. So if we would have used a category Category:Successful project then we could have created only the following query:

{{#ask: [[Category:Project]]
| ?Category:Successful project#success,failure

I this case, an extra cloumn labelled "Sucessful" appears again, but now showing success for all results that belong to the category Successful, and showing failure for all other cases (including those where the status may be unknown).

In both of the above cases, it is possible to use "=" to change the label of the rsul column, as usual, e.g.:

{{#ask: [[Category:Project]]
| ?successful#success,failure=Success status

A special formatting symbol for Booleans is the lower-case letter x. When given as a text for displaying results, SMW will use an X that resembles a cross for true.

{{#ask: [[Category:Project]]
| ?successful#x

This would show a cross for all cases where the property is set to true, and nothing if it is false or unset. Finally, the labels given for true and false (or category membership and non-membership) can also be special symbols or images, and may also be empty to show nothing. However, at least the comma should always be set. So to display a tick (actually a square root symbol) for true one could use:

{{#ask: [[Category:Project]]
| ?successful#√,

Booleans in other languages

As mentioned above you may enter "true" or "false", also 1/0, yes/no, t/f, and y/n as possible values for booleans. To find out about (and possibly change) the booleans used in your language, see the messages MediaWiki:Smw_true_words and MediaWiki:Smw_false_words.

See the effect for this wiki at: Help:Examples for Boolean Options

Localization based on user language is provided with the #LOCL output formatting option. Furthermore, if a page has set a specific page content language 1 then the DV tries to match local values against that language 2 instead of the global content language.


This documentation page applies to all SMW versions from 1.0 to the most current version.
      Other languages: deruzh-hans

Help:Type Boolean en 1.0