7

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?

sveti petar
  • 3,637
  • 13
  • 67
  • 144

3 Answers3

14

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.

Dwza
  • 6,494
  • 6
  • 41
  • 73
Sergei Guk
  • 1,775
  • 1
  • 13
  • 12
  • Where is this cofing/config.inc.php file. I am using XAMPP. and in XAMPP there is only 1 cofing.inc.php file located inside the phpmyadmin folder and there is nothing related to this??? – Sizzling Code Aug 26 '14 at 23:38
  • My answer was about Prestashop 1.5, just check @Rocker Maruf's answer below for Prestashop 1.6+ – Sergei Guk Aug 28 '14 at 09:06
2

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.

gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79
Rocker Maruf
  • 509
  • 5
  • 6
0

Set the $error_reporting variable.

See http://www.smarty.net/docsv2/en/variable.error.reporting.tpl

Dan Poltawski
  • 575
  • 4
  • 12
  • Sorry but where exactly should I set this? Doing `$error_reporting = 1;` in the file itself doesn't seem to do anything. Adding `$smarty->error_reporting = E_ALL & ~E_NOTICE;` also does nothing. – sveti petar Nov 28 '12 at 13:50