Reputation: 3
I am having an issue, which is due to syntax or the parser or both:
My goal is to call a query having alternative values for one property, collected on the same page as the query through a form.
This query works:
{{#ask:
[[Category:Category-A]]
[[Property-A::Value-A||Value-B]]
|?Property-A
|format=tree
|parent=PartOf
}}
Now, I need to figure out, how to pass multiple, different values for Property-A to the query. How do I do that?
Furthermore, there could be 1 or more of the values, depending on how the form is being answered. How do I make the query flexible in terms of values being passed to it?
I played around with a template, such as {{!!}} to enter the '||', but I am not sure, how to get the result into the query:
{{#set:Variable=Value-A;Value-B|+sep=;}}
{{#show: {{PAGENAME}}|?Variable|format=plainlist|valuesep={{!!}}}}
{{#set:TempString={{#show: {{PAGENAME}}|?Variable|format=plainlist|valuesep={{!!}}}}}}
Query:
{{#ask:
[[Category:Category-A]]
[[Property-A::TempString]]
...
This does not work, since when I set the Variable on a property type of 'page', it doesn't accept the resulting TempString in the Query and when I set the property type of 'text', it doesn't accept the values being assigned to it.
For the flexible length bit, is there perhaps a place for the following code snippet?
{{#if: {{{Value-A|}}}|[[Variable::{{{Value-A}}}]]|}}
Anyone having an idea? I shouldn't be the only one trying to do this I would imagine.
Best Regards,
Ruedi
Upvotes: 0
Views: 63
Reputation: 1
by using #arraymap from Page Forms extension,
customize "Property-A OR YourFormLabelForProperty-A" : you need to set this value the same as the one in your form
{{#ask:
{{#arraymap:{{{Property-A_likeYourFormLabel|}}}|,|xxx|[[Property-A_likeInYourTemplateProperty::xxx]]|OR}}
...
}}
Upvotes: 0
Reputation: 4554
In wikitext, you should never rely on parsing order, and you are doing exactly this.
Every time that parsing order becomes essential, it is a task for Scribunto. Therefore, install Scribunto, define Lua Module:Ask
like this:
return {
values = function (frame)
local property = frame.args.property
local domain = frame.domain or ''
local values = {}
for _, value in ipairs (frame.args) do
values [#values + 1] = value
end
return frame:callParserFunction ('#ask', {
domain .. ' [[' .. property .. '::' .. table.concat (values, '||') .. ']]',
'?Printout-1',
'?Printout-2',
format = 'ul'
})
end
}
and invoke it with: {{#invoke:Ask|values|domain=[[Category:Category-A]]|property=Property-A|Value-A|Value-B}}
.
You could also install Semantic Scribunto for complex processing of structured query results.
UPD: a variant with possible value passed as a list, in a single string:
return {
values = function (frame)
local property = frame.args.property
local domain = frame.domain or ''
local values = mw.text.split (
frame.args.values or '',
frame.args.separator or ',%s*'
)
return frame:callParserFunction ('#ask', {
domain .. ' [[' .. property .. '::' .. table.concat (values, '||') .. ']]',
'?Printout-1',
'?Printout-2',
format = 'ul'
})
end
}
Invocation: {{#invoke:Ask|values|domain=[[Category:Category-A]]|property=Property-A|values=Value-A, Value-B}}
.
Upvotes: 1