Topic on Extension talk:Variables

would like to use #ifexpr: with #len: and #var:

8
Summary by MGChecker

Interactions of parser functions with references are complex, and unexpected behavior is unlikely to be fixed.

Gunnar.offel (talkcontribs)

I would like to use a expression to check a length.

{{#ifexpr:{{#len:{{#var:refs|}} }} > 10 | [..]

That provides no exeption, as far as good, but the

{{#len:{{#var:refs|}} }}

provides always 0 so the check doesn't work. Any Idea how to solve the issue or change the behavior?

____ i wrote the ask allready in Help_talk:Extension:ParserFunctions but maybe this point is the better choice.

Gunnar.offel (talkcontribs)

i tried also the given alternatives, but sadly they also doesn't work in my case. :S

MGChecker (talkcontribs)

Are you sure the refs variable is populated? If this is not the case, you get an empty string out of `refs`, matching your reports.

MGChecker (talkcontribs)

At least

{{#vardefineecho: refs | Tree }}
{{#ifeq: {{#var: refs }} | Tree | 1 | 0 }}

works properly for me, on the contrary to the reports on the ParserFunctions. Sadly, I have no wiki with StringFunctions and Variables at hand at the moment, so I can not reproduce your claims.

Dinoguy1000 (talkcontribs)

On my own wiki with ParserFunctions, StringFunctions, and Variables, I have never had any issue using the three together as described here. @Gunnar.offel: could you provide what versions of MediaWiki, Ext:ParserFunctions, and Ext:Variables your wiki has installed?

Dinoguy1000 (talkcontribs)

Actually, based on the name of the variable, is it meant to store references? Trying to work with <ref> tags with parser functions is difficult, because of the special parsing that takes place around them. If it's an option for you, you may have better luck using Scribunto/Lua for this instead.

Gunnar.offel (talkcontribs)

@MGChecker, if i use vardefineecho and also if i call the #var it outputs the wanted things. So i'm pretty sure, that i populate the variable. i just can't get it to work with the parser function.


@Dinoguy1000: sure, - MediaWiki 1.34.0 - ParserFunctions 1.6.0 - Variables 2.5.1 (d6ce860) 08:16, 4. Sep. 2019

Yes, the variable stores the references and it works, but at the moment not in the parser functions. actually i just want to hide an empty table and only show if content is available. That's a big gun on a little problem, sure but keeps me up for a better understanding how to use/solve the extension.

MGChecker (talkcontribs)

As Dinoguy said, this is properly a really hard problem. References are a really complicated feature, kind of using variables as internal counter as well, and being evaluated at a different time during parsing. This leads to many features of stock MediaWiki already to behave weird when used together with references – especially advanced syntax features offered by extensions.

What is properly happening here that the references are not populated at the (quite early) point during parsing when variables are evaluated in this logic. I do not know exactly what is happening, but trying to get the references at multiple points, at different parsing stages, is quite typical for problems related to references.

Hence, your references var is always empty for parser functions. On the other hand, variables not encapsulated into the template tree can properly evaluated properly.