Semanticmediawiki: Allow passing of arbitrary parameters into template calls of result formats

Created on 10 Feb 2019  路  4Comments  路  Source: SemanticMediaWiki/SemanticMediaWiki

Setup and configuration

  • SMW version: 3.0.0

Issue

The userparam parameter can be used to pass values to the #userparam parameter for template calls of several result formats. This has two drawbacks:

  1. you are limited to pass only one parameter (advanced use cases may require multiple)
  2. the template needs to be adapted for SMW

Both could be resolved by introducing a syntax like:

| param <name> = <value>

which would be equivalent to | <name> = <value> when calling the template directly.

enhancement

Most helpful comment

And I think this should be possible with stock MW + SMW without further extensions.

I understand the sentiment but someone has to invest (time, testing, writing code etc.) and commit to such endeavor and while it seems from a user perspective as "... should be possible with stock ..." this extension doesn't maintain itself therefore people who want a feature (or something to be a default functionality) to step up.

I wanted to give an early feedback so others can engage and discuss (as I won't have time for any commitment on this).

All 4 comments

| param <name> = <value>

A ResultPrinter is gating the parameter invocation with only those registered (defined per result printer, pre-execution) being available for further processing.

Changing the way this is implemented would require some work.

Substitution template

You could use a substitution template as in:

{{#ask: [[Has text::+]]
 |?Has text
 |userparam={{param|foo=1|bar=2}}
 |template=Test
 |format=template
 |named args=true
}}
  • Template:Test will contain a reference to {{{#userparam}}}
  • Template:Param (=={{param|foo=1|bar=2}}) is used as substitution so that you can refer to individual named parameters like {{{foo}}} or {{{bar}}} from within this template or act on its behalf

#json_val parser function

Without having SMW to do anything you could also use (transform relevant parameters into a valid JSON string):

{{#ask: [[Has text::+]]
 |?Has text
 |userparam={"foo":"abc", "bar":"def"}
 |template=Test
 |format=template
 |named args=true
}}

Later in the template (given that someone provides such parser function) rely on something like {{#json_val:{{{#userparam}}}|bar}} to resolve the content of the JSON string and return the corresponding value of the selected parameter.

Thanks for the quick response! I am afraid I don't quite get how Template:Param would work / help, can you give an example? And I think this should be possible with stock MW + SMW without further extensions.

And I think this should be possible with stock MW + SMW without further extensions.

I understand the sentiment but someone has to invest (time, testing, writing code etc.) and commit to such endeavor and while it seems from a user perspective as "... should be possible with stock ..." this extension doesn't maintain itself therefore people who want a feature (or something to be a default functionality) to step up.

I wanted to give an early feedback so others can engage and discuss (as I won't have time for any commitment on this).

I usually write template = template{{!}}param1=value1{{!}}param2=value2 in {{#ask:}}.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JeroenDeDauw picture JeroenDeDauw  路  3Comments

MvGulik picture MvGulik  路  4Comments

mwjames picture mwjames  路  3Comments

seth2740 picture seth2740  路  3Comments

krabina picture krabina  路  4Comments