Post by head_dunce » Wed May 08, 2019 5:47 am

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?

Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020


Active Member

Posts

Joined
Thu Apr 04, 2019 11:50 pm

Post by straightlight » Wed May 08, 2019 5:48 am


The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by head_dunce » Wed May 08, 2019 5:56 am

Ah, thanks!

Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020


Active Member

Posts

Joined
Thu Apr 04, 2019 11:50 pm

Post by head_dunce » Wed May 08, 2019 9:46 am

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

Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020


Active Member

Posts

Joined
Thu Apr 04, 2019 11:50 pm

Post by letxobnav » 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.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by head_dunce » Wed May 08, 2019 6:52 pm

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?

Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020


Active Member

Posts

Joined
Thu Apr 04, 2019 11:50 pm

Post by letxobnav » Wed May 08, 2019 7:30 pm

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.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by straightlight » Wed May 08, 2019 7:38 pm

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.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by head_dunce » Thu May 09, 2019 12:11 am

Figured it out.
Edit this file -
catalog/controller/event/theme.php

Code: Select all

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

Code: Select all

$config = array('autoescape'	=> false,'debug' => true,);
after this line

Code: Select all

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

Code: Select all

$this->twig->addExtension(new \Twig_Extension_Debug());
Last edited by straightlight on Fri Mar 06, 2020 12:15 am, edited 1 time in total.
Reason: Added code tags.

Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020


Active Member

Posts

Joined
Thu Apr 04, 2019 11:50 pm

Post by jeffz2014 » Fri Mar 06, 2020 12:14 am

This would work without any addon.
Tested with Twig version: 1.24.2 ... might work with later.
It is done in accordance to Twig official docs: https://twig.symfony.com/doc/1.x/functions/dump.html

It is very simple to enable it.

step 1:

Find file:

Code: Select all

\Twig\Environment.php
It should be in a Twig root folder.
Or search Twig folder for class: Twig_Environment

Inside of method in Twig_Environment:

Code: Select all

public function __construct()
... add:

Code: Select all

$this->addExtension(new Twig_Extension_Debug());
I suggest adding above just below code:

Code: Select all

$this->staging = new Twig_Extension_Staging();
step 2:
In same file as in step 1, in same method:

Code: Select all

public function __construct()
... find array: $options

First key/value pair change to:

Code: Select all

'debug' => TWIG_DEBUG,
step 3:
Find main OpenCart configure.php - one in root folder, not admin one.
And add:

Code: Select all

define('TWIG_DEBUG', true);
When you want debugging and dump() var available, set it to true, when you want it disabled, set it to false.
So, TWIG_DEBUG constant is, so you do not have to look for that deep hidden Twig class to enable / disable debug.

Newbie

Posts

Joined
Tue Dec 09, 2014 6:48 am

Post by straightlight » Fri Mar 06, 2020 12:17 am

Find main OpenCart configure.php - one in root folder, not admin one.
That file name does not exist out-of-the-box.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Quino » Fri Mar 06, 2020 12:39 am

config.php it is.

New member

Posts

Joined
Fri Feb 28, 2020 1:19 am
Who is online

Users browsing this forum: No registered users and 13 guests