Join data from two pages into one table

I found myself yesterday in a situation where I wanted to list in a table data properties scattered over two wiki pages for each row. That is, given one table row, one column was found on one page, while the other column was found on another page. After asking on #semantic-mediawiki, faceface explained me how to do this, and to write it up here. The key here is to use templates.

I had these semantic pages:


 * http://drugmet.rilspace.org/wiki/FC(F)(F)CO, which links semantically with HasPKaValue to
 * http://drugmet.rilspace.org/wiki/An_experimental_pKa_value_from_10.1021/ja01489a008_for_FC(F)(F)CO

Both pages have data properties associated: SIO_000300 (yeah, don't ask) to a value, and Label on the first.

Here's the query I have on http://drugmet.rilspace.org/wiki/All_pKa_values:

The templates (the crucial part below) create the table. The main template part uses a #show statement to get the SIO_0003000 property from the second page: #show: | ? SIO 000300. The first page is what is being queried for with #ask: [ [ HasPKaValue::+ ] ].

PKaValueTemplate
http://drugmet.rilspace.org/wiki/Template:PKaValueTemplate look like:

| ||  |-

PKaValueTemplateHeader
http://drugmet.rilspace.org/wiki/Template:PKaValueTemplateHeader look like:

{| class="wikitable sortable" ! Molecule !! pKa |-

PKaValueTemplateFooter
http://drugmet.rilspace.org/wiki/Template:PKaValueTemplateFooter look like:


 * }