Page 1 of 1

How to dump twig variables?

Posted: Wed May 08, 2019 5:47 am
by head_dunce
I'm trying to modify the Twig stuff, but I don't know what the variables contain, so I assume I need to dump them.
So reading this -
https://twig.symfony.com/doc/2.x/functions/dump.html

It looks like the Twig loader is in -
/var/www/html/catalog/controller/event/theme.php

But I'm not sure if that DebugExtension is somewhere? Anyone install the Twig dump that can help?

Re: How to dump twig variables?

Posted: Wed May 08, 2019 5:48 am
by straightlight

Re: How to dump twig variables?

Posted: Wed May 08, 2019 5:56 am
by head_dunce
Ah, thanks!

Re: How to dump twig variables?

Posted: Wed May 08, 2019 9:46 am
by head_dunce
Didn't work

Code: Select all

Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'Unknown "dump" function in "__string_template__5b2a435a5d40c2041f16a317c7f3982355f9d27bc7bde73b3a0933f726f087a3" at line 26.' in /var/www/html/system/library/template/Twig/ExpressionParser.php:574 Stack trace: #0 /var/www/html/system/library/template/Twig/ExpressionParser.php(351): Twig_ExpressionParser->getFunctionNodeClass('dump', 26) #1 /var/www/html/system/library/template/Twig/ExpressionParser.php(144): Twig_ExpressionParser->getFunctionNode('dump', 26) #2 /var/www/html/system/library/template/Twig/ExpressionParser.php(84): Twig_ExpressionParser->parsePrimaryExpression() #3 /var/www/html/system/library/template/Twig/ExpressionParser.php(41): Twig_ExpressionParser->getPrimary() #4 /var/www/html/system/library/template/Twig/Parser.php(144): Twig_ExpressionParser->parseExpression() #5 /var/www/html/system/library/template/Twig/TokenParser/For.php(40): Twig_Parser->subparse(Array) #6 /var/www/html/system/library/template/Twig/Parser.php(187): Twig_TokenPar in /var/www/html/system/library/template/Twig/ExpressionParser.php on line 574

Re: How to dump twig variables?

Posted: Wed May 08, 2019 1:34 pm
by letxobnav
By design, the dump() function is only available in the dev and test environments, to avoid leaking sensitive information in production. In fact, trying to use the dump() function in the prod environment will result in a PHP error.

Re: How to dump twig variables?

Posted: Wed May 08, 2019 6:52 pm
by head_dunce
letxobnav wrote:
Wed May 08, 2019 1:34 pm
By design, the dump() function is only available in the dev and test environments, to avoid leaking sensitive information in production. In fact, trying to use the dump() function in the prod environment will result in a PHP error.
Yes, I know. So how did you get it to work?

Re: How to dump twig variables?

Posted: Wed May 08, 2019 7:30 pm
by letxobnav
I didn't, I have no need to dump anything related to twig.
If I need to check what I send to twig, I dump those variables in my php error log from the controller.

Besides, I only use twig to display variables and use as little twig logic as possible, for the rest I say far away from it.

Re: How to dump twig variables?

Posted: Wed May 08, 2019 7:38 pm
by straightlight
Using stored logs from PHP does not provide TWIG structures. However, you could contact the extension developer to ask how his extension works if no detailed documentation has been provided about it. As an alternative, there are also other extensions on the Marketplace you could use simply by using the Marketplace search form.

Re: How to dump twig variables?

Posted: Thu May 09, 2019 12:11 am
by head_dunce
Figured it out.
Edit this file -
catalog/controller/event/theme.php

$config = array('autoescape' => false);
to
$config = array('autoescape' => false,'debug' => true,);

after this line
$this->twig = new \Twig_Environment($loader, $config);]
add this line
$this->twig->addExtension(new \Twig_Extension_Debug());