odan / twig-translation

A Twig Translation Extension
MIT License
15 stars 3 forks source link

Problems with bin/parse-twig.php #3

Closed killua-eu closed 4 years ago

killua-eu commented 4 years ago

I modified the bin/parse-twig.php suggested in https://github.com/odan/twig-translation#parsing-twig-files slightly to fit into my app (https://github.com/vaizard/glued-skeleton/blob/master/glued/Core/Bin/parse-twig.php). Upon running the script, I'm getting

root@gdev:/var/www/html/glued-skeleton# php glued/Core/Bin/parse-twig.php 
PHP Notice:  Undefined index: SERVER_NAME in /var/www/html/glued-skeleton/glued/settings.php on line 109
PHP Notice:  Undefined index: SERVER_NAME in /var/www/html/glued-skeleton/glued/settings.php on line 110
PHP Notice:  Undefined index: SERVER_NAME in /var/www/html/glued-skeleton/glued/settings.php on line 111
Parsing: Calendar/Views/browse.twig
Parsing: Calendar/Views/manage.twig
Parsing: Core/Views/accounts.read.twig
PHP Fatal error:  Uncaught Twig\Error\SyntaxError: Unknown "url_for" function. in /var/www/html/glued-skeleton/glued/Core/Views/accounts.read.twig:17
Stack trace:
#0 /var/www/html/glued-skeleton/vendor/twig/twig/src/ExpressionParser.php(451): Twig\ExpressionParser->getFunctionNodeClass()
#1 /var/www/html/glued-skeleton/vendor/twig/twig/src/ExpressionParser.php(235): Twig\ExpressionParser->getFunctionNode()
#2 /var/www/html/glued-skeleton/vendor/twig/twig/src/ExpressionParser.php(175): Twig\ExpressionParser->parsePrimaryExpression()
#3 /var/www/html/glued-skeleton/vendor/twig/twig/src/ExpressionParser.php(70): Twig\ExpressionParser->getPrimary()
#4 /var/www/html/glued-skeleton/vendor/twig/twig/src/Parser.php(142): Twig\ExpressionParser->parseExpression()
#5 /var/www/html/glued-skeleton/vendor/twig/twig/src/TokenParser/BlockTokenParser.php(45): Twig\Parser->subparse()
#6 /var/www/html/glued-skeleton/vendor/twig/twig/src/Parser.php(185): Twig\TokenParser\BlockTokenParser->parse()
#7 /var/www/html/glued-skeleton/vendor/twig/twig/s in /var/www/html/glued-skeleton/glued/Core/Views/accounts.read.twig on line 17

I'm not sure why I get the Unknown "url_for" function error. It seems that the slimphp/Twig-View somehow doesn't get loaded, even though I'm getting $twig from the container, so I should be 1:1 with the rest of the app. I'm really at loss how to fix this. Got any ideas you could kindly suggest?

Thanks, P.

odan commented 4 years ago

I think url_for doesn't exists anymore, it should be path_for.

odan commented 4 years ago

Can you try to replace url_for with path_for?

killua-eu commented 4 years ago

Sorry for the late reply. Its the other way around, path_for doesn't exist any more (at least not in the latest https://github.com/slimphp/Twig-View#custom-template-functions Using path_for gets me

Twig \ Error \ SyntaxError
Unknown "path_for" function.

when rendering a page, so there's no backward compat too I could rely on.

odan commented 4 years ago

As first I would recommend that you use the the same container instance as you would use for your Slim app. Don't build a new container for this special use case. If you use the same container and app instance then it should work like in your application.

PS: I just updated the example: https://github.com/odan/twig-translation/blob/master/README.md#parsing-twig-files

A Symfony command example

killua-eu commented 4 years ago

Uh, wow. I was actually building a container and including the slim app one a few lines later. I honestly didn't see that. Probably some really bad kind of code dyslexia or ... (fill in your favourite excuse for looking at your code without actually reading in).

For some reason the path_for / url_for thing disappeared too and I'm unable to replicate it. Sorry for the confusion, closing this issue.