Broken with Twig 2.10.0
Twig 2.10.0 was recently released and it seems to be breaking this extension with the following message when calling the 'filter' filter :
Unexpected token "arrow function" of value "=>".
Have the same - had to switch back to twig 2.9
Same error with Twig 1.41.0 Downgrading to Twig 1.39.1 worked
Same here. I had to downgrade twig from 2.11 to ~2.9
I just realized that filter and map are included in Twig 2.10 and Twig 1.41 thus making this extension unnecessary in those cases.
@jean-gui yeah, right - I use it for group_by functionality
I could be wrong, but it seems like the main issue is that this extension's => token now conflicts with Twig's built-in => token. As a (hopefully temporary) workaround, I forked the repo and changed the token to ==>. This was line 22 and 28 of LambdaExtension.php:
public function getOperators()
{
return [
[
- '=>' => [
+ '==>' => [
'precedence' => 0,
'class' => '\DPolac\TwigLambda\NodeExpression\SimpleLambda'
],
],
[
- '=>' => [
+ '==>' => [
'precedence' => 0,
'class' => '\DPolac\TwigLambda\NodeExpression\LambdaWithArguments',
'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT
],
';' => [
'precedence' => 5,
'class' => '\DPolac\TwigLambda\NodeExpression\Arguments',
'associativity' => \Twig_ExpressionParser::OPERATOR_RIGHT
],
]
];
}
I then updated my template code to use ==> instead of =>, i.e.:
{% set myVar = data|group_by(==> ...) %}
I'm not sure what other better option there is besides than changing twig-lambda's token.
@gmhenderson, you are correct. I exended the LambdaExtension class and overrode the getOperators() method and it works again as expected.