4

I would like to display in the same query properties of a page which is related to the pages im querying for.

Let's say I would like to query all the pages in the City category, which are located in Germany, and I want to display the title of the page, but also I want to display the surface data of Germany, for example.

Something like this: {{#ask: [[Category:City]] [[location::Germany]] |?mainlabel |?Location.surface }}

I know this wont work, but you can see what I want to achieve.

unor
  • 92,415
  • 26
  • 211
  • 360

1 Answers1

3

I'm not sure if there's a way to nest queries directly inside other queries. The normal method of doing it is using a template. So you might define a template (or subpage of the template if this going into a template) called {{tablerow}} that consists of:

<includeonly>
|- valign="top"
| [[{{{1|}}}]]
| {{#show: {{{1|}}} | ?surface }}</includeonly>

The <includeonly> tags are important for reasons I don't really understand, it produces errors sometimes if you leave them out. Then you just run an #ask query with format = template. (You can build the header into the query, but I find it simpler to just put it outside.)

{| class="wikitable smwtable sortable"
|- valign="bottom"
! [[City]]
! [[Surface]]

{{#ask: [[Category:City]] [[location::Germany]]
  | format   = template
  | template = tablerow
  | link     = none
}}

|}

That will punch each result returned by the query through the template as {{{1}}} and generate a row based on it. If you have other data to return from the main query, additional properties that you ask for will come out as consecutive unnamed parameters (so if you include | ?population, that will go into the template as {{{2}}} and will need to be added to the row structure or it will be dropped).

  • Includeonly tags specify the portion of the template to only be rendered by the pages invoking the template. As opposed to the noinlude tags, which contain content that will only be rendered by the template page, not the pages invoking it. Everything outside these tags would be rendered by both. For an example in use, see: http://openei.org/wiki/Template:SampleTemplate – Jon Weers Aug 01 '13 at 02:19
  • Well, yes, I know what the tags do generally. I meant that in the specific case of helper templates for semantic mediawiki `{{#ask}}` functions I don't know why they're necessary. Even though the only text in the template is the section to be transcluded, sometimes it won't work unless you wrap the entire template in `` tags. I've not encountered any other situation where that's the case. – Michael Chidester Aug 01 '13 at 14:51