I'm trying to create a template using the random selection. <choose> <option weight="{{#expr:1 + {{{add|0}}}}}>Apple</option> </choose>
But it returns nothing, making me think the expression is not being evaluated properly.
I'm trying to create a template using the random selection. <choose> <option weight="{{#expr:1 + {{{add|0}}}}}>Apple</option> </choose>
But it returns nothing, making me think the expression is not being evaluated properly.
This is the standard "can't mix parser functions and XML-style tags" issue. You'll need to use #tag
to work around this, though it's a bit more involved than usual since RandomSelection involves two tags:
{{ #tag: choose | {{ #tag: option |Apple | weight="{{ #expr: 1 + {{{add|0}}} }}" }} }}
(The whitespace in this code is generally optional and can be removed if you wish, but you shouldn't add any whitespace between each option and its preceding pipe, since this whitespace will be included in the output.)
Hello, is it possible to specify a weight for options when using the parser function?
It's literally right there on the extension page: Extension:RandomSelection#Parameters to <option>.
This is for the tags, is there none for the parser function?
Looking at the source code for the parser function, it doesn't appear so (though my PHP comprehension isn't especially strong).
According to the parser function section, there should be a pipe before every choice including the first. However, on my wiki that leads to an empty choice being selected as often as any other result. Compare:
Why {{#choose:not|both}}?
and
Why {{#choose:|not|both}}?
several times to see for yourselves.
I also couldn't find a way to specify the uncached parameter with this syntax.
For some reason after my wiki got updated to 1.33 all texts inside option tags starting with a whitespace are parsed as it happens when you start a new line beginning with a whitespace: a block in monospace font. Before, it just treated it as regular whitespace. I guess it's not intentional.Wedhro (talk) 17:46, 4 July 2019 (UTC)
Though this does not sound nice, no doubt, I think that this should be the expected behaviour. --[[kgh]] (talk) 21:52, 4 July 2019 (UTC)
This is indeed an intentional change, done to make the extension more cache-friendly. See the relevant commit.
Well the commit has been reverted now, but my intention was not to change how the tag worked at all, so any changes to whitespace handling is accidental. Could you post an example of the change?