Templates are awesome.
As I’ve written about before, we use Semantic MediaWiki extensively at work. One way we use it is to handle research requests for or Solution Architecture team. We have a customer-facing form1 for all requests and the resulting page is accessible for anyone across the organization – sharing our findings beyond the original requester.
For any requests submitted, the form creates a new wiki article as a sub page of “Research”. This is done by adding an attribute of “query string=super_page=Research” to the form.
It helps us to keep things organized by denoting which pages are specific to research vs. general wiki pages.
The problem is how semantic queries display pages that have a ‘super page’ prefix. By default the query results will show the super page as part of the formatting.
See the “Research/” prefix on every item? That’s rather redundant (and ugly), so I sought out a way to remove the ‘Research/’ prefix when displaying the results, but still provide the correct link to the sub page.
The magic is two-part. First, you need to make sure your #ask query has the attribute of “link” set to none (link=none) and “format” set to template (format=template)2. This strips out any default formatting of the results. Here’s the #ask query we’re using. Note you’ll obviously want to change the variables to fit your properties.
{{#ask: [[Category:Research]]
|?Research_Level_Requested
|?Research_Submitted_Date
|limit=15
|link=none
|format=template
|template=Research Results Template
|order=DESC
|default=No related research found. Submit a [[Research]] request?
|searchlabel=”’15 Most Recent Research Requests Loaded. View all Research?”’
}}
Then, for your template you’ll use the #arraymap function to format the output.
{{#arraymap:{{{1}}}|Research/|noSuperName|[[Research/noSuperName|noSuperName]]}} – {{{2}}} – {{{3}}}
What this does is for each result it removes the “super-page” prefix (in this case Research/) from the first property returned – the page name.
{{#arraymap:{{{1}}}|Research/|
It then replaces it with the variable noSuperName.
|Research/|noSuperName|
Finally we actually construct a normal internal wiki hyperlink by adding “Research/” and the variable together in the proper syntax.
[[Research/NoSuperName|NoSuperName]]
The remaining variables {{{2}}} and {{{3}}} are called as normal and a break tag is added to keep each query result on its own line.
The result is something like the following screenshot.
You will then have nicely formatted results that are easier to digest.
I hope this helps those looking to extend the semantic queries and produce clean, repeatable results. Let me know in the comments if you have any questions or ideas of your own.
Hi – the use of #arraymap is quite clever, though the easier way to get part of a wiki page’s name is to use the #titleparts parser function, defined in the ParserFunctions extension (formerly StringFunctions).
Good to know. I’ll have to look into that!