Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken with Twig 2.10.0 #11

Open
jean-gui opened this issue May 14, 2019 · 7 comments
Open

Broken with Twig 2.10.0 #11

jean-gui opened this issue May 14, 2019 · 7 comments

Comments

@jean-gui
Copy link

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 "=>".

@crabnky
Copy link

crabnky commented May 15, 2019

Have the same - had to switch back to twig 2.9

@DevManen
Copy link

Same error with Twig 1.41.0
Downgrading to Twig 1.39.1 worked

@vialcollet
Copy link

Same here.
I had to downgrade twig from 2.11 to ~2.9

@jean-gui
Copy link
Author

jean-gui commented Jun 4, 2019

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.

@crabnky
Copy link

crabnky commented Jun 6, 2019

@jean-gui yeah, right - I use it for group_by functionality

@gmhenderson
Copy link

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.

jcherniak added a commit to pinfirestudios/twig-lambda that referenced this issue Jun 13, 2019
@blupointmedia
Copy link

@gmhenderson, you are correct. I exended the LambdaExtension class and overrode the getOperators() method and it works again as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants