SMW queries

Here you can see some examples for simple queries using the properties of a wiki page. This functionality is provided by the bundled extension Semantic MediaWiki. You can add these queries to any wiki page.

Content droplet "Data query"  v4.3+[edit | edit source]

Starting with BlueSpice 4.3, basic SMW data queries can be added directly with the Content droplet "Data query":

  1. Click on the Content droplets menu item in the visual editor.
  2. Select Data query under Lists.
    Screenshot of the Content droplet selection for "Lists"
    Content droplet "Data query"
  3. Click Insert. This opens the droplet inspector.
  4. Fill in the query options (parameter). Each setting has a tooltip that explains exactly what values you can enter.
    Data query parameters
    Data query parameters
  5. Click Save.

Creating page lists[edit | edit source]

If you need more flexible, customizable queries, you can add the queries directly in source edit mode. Below are a few examples to get you started.

Show pages in a particular namespace[edit | edit source]

{{#ask:
[[:+]]  <!-- find all pages in the main namespace -->
[[Modification date::+]]<!-- necessary to filter deleted pages -->
|format=ul
|limit=4
}}

Output example in list style format:


... further results


Notes:


[[:+]] shows pages from the Main namespace.

[[Myspace:+]] shows pages from the namespace Myspace.

[[:+||Help:+]] shows pages from both the Main namespace and the namespace Help (=OR argument)

Output in category style[edit | edit source]

{{#ask:
[[:+]][[Modification date::+]]
|format=category
|limit=12
}}
Output example:

Show pages from a category[edit | edit source]

{{#ask: 
[[Category:Administration]] 
| limit=4 
| searchlabel=
| format=ol 
}}
  1. Config manager
  2. Extended statistics
  3. Footer
  4. Main navigation

Pages that start with the same page name string[edit | edit source]

{{#ask: 
[[~Visu*]][[:+||Manual:+]]
[[Modification date::+]]<!-- necessary to filter deleted pages -->
| limit=5 
| searchlabel=
| format=ol 
}}
List of pages in the Main namespace and in the namespace Manual that begin with "Visu".


Results format: Table[edit | edit source]

Format "broadtable"[edit | edit source]

{{#ask: 
[[~Visu*]][[:+||Manual:+]]
[[Modification date::+]]<!-- necessary to filter deleted pages -->
| limit=5 
| searchlabel=
| format=broadtable
}}



Format "datatable"[edit | edit source]

{{#ask: 
[[~Visu*]][[:+||Handbuch:+]]
[[Modification date::+]]<!-- necessary to filter deleted pages -->
| limit=5 
| searchlabel=
| format=table
| class=datatable
}}
Important!The format declaration
|format=datatable 
currently does not work with the BlueSpice skin. Instead, use the following syntax:
|format=table
|class=datatable




Date queries[edit | edit source]

Today[edit | edit source]

To ask for all pages that have been approved today:
{{#ask:
[[QM/Approval date::>>{{#time:Y-m-d|now -1day}}]]
}}

Search operators[edit | edit source]

If you want to look for results in a particular range, you can use search operators. See: https://semantic-mediawiki.org/wiki/Help:Search_operators#comparators

Templates[edit | edit source]

Customized output formats can be created using templates. The documentation for this can be found at semantic-mediawiki.org.

Here we show you some useful tips when working with templates.

Suppressing the namespace prefix[edit | edit source]

By default, the namespace prefix of a page is suppressed in the output formats "ul", "ol" (and other formats). However, if you are working with a template and therefore use the link=none parameter in the ask query, because you generate the link in the template yourself, then the page name is displayed with the namespace prefix. Sample query of all pages in the QM namespace:
{{#ask: QM:++Property "Modification date" has a restricted application area and cannot be used as annotation property by a user.
|format=plaintext
|template=mytemplate
|link=none
}}
The output here is in the format QM:My Page. To remove the namespace prefix, use the following syntax in the template, e.g. to generate an unordered list:
*[[{{FULLPAGENAME:{{{1}}}}}|{{PAGENAME:{{{1}}}}}]]
In this example, the full page name is linked via the "magic word" {{FULLPAGENAME}} and the page name without namespace prefix {{PAGENAME}} is used as the link label. The resulting output is My Page.

Related info


Discussions