I've been working with PHP for a while, but fairly new to Smarty.
I'm working with Prestashop and I've noticed Smarty seems to eat up all PHP errors - when there's an error in the PHP code, the .tpl file just outputs a blank page. I've been trying but I can't get Smarty to display whatever the PHP code outputs, even if there's an error.
PHP error reporting is set to show errors.
So, for instance, let's say this is the example.php file:
<?php
//included classes etc go here, irrelevant for this issue
error_reporting(E_ALL ^ E_NOTICE);
echo obvious wrong syntax"
?>
This file is connected to example.tpl which fits the output in a template block.
Obviously, it should throw an error. How do I make Smarty actually display that error?
To activate debug mode, go to config/config.inc.php
Find the following lines and chage off
to on
for the first one and set to true the second
/* Debug only */
@ini_set('display_errors', 'on');
define('_PS_DEBUG_SQL_', true);
This will display PHP and SQL errors (this would probably be enough for you to resolve "blank page").
There is also a blog post on prestashop site about p() and d() methods and how to track exceptions
To activate templates debug in Prestashop version older than 1.5,go to config/smarty.config.inc.php
Find the following line and set it to true
$smarty->debugging = true;
When you refresh your page, themes/debug.tpl
should be rendered.
To activate templates debug in Prestashop 1.5+ you can enable Smarty debugging via Admin panel
Preferences > Performance > Smarty
and set Always open console
but console will be opened for everyone ( not good for live site :) )
or set Open console with URL parameter (SMARTY_DEBUG)
and add ?SMARTY_DEBUG
to the end of your URL to see console
Hope this helps.
I've seen @Sergei Guk's answer and off-course, it's a pretty good answer. However, prestashop has since released version 1.6.
So if you want to show all the errors in prestashop v 1.6.0.6, you just need to go config/defines.inc.php
Replace define('_PS_MODE_DEV_', false);
with define('_PS_MODE_DEV_', true);
What it actually does is set a constant and in the next line it checks if "_PS_MODE_DEV_" is true then it will show all kinds of errors in prestashop
if (_PS_MODE_DEV_)
{
@ini_set('display_errors', 'on');
@error_reporting(E_ALL | E_STRICT);
define('_PS_DEBUG_SQL_', true);
}
else
{
@ini_set('display_errors', 'off');
define('_PS_DEBUG_SQL_', false);
}
I have tested it and it works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With