Jump to content

Guide - Enable Smarty Console on the new Prestashop 1.6


Recommended Posts

lol.png
Yesterday was launched the new awesome Prestashop version, and the first "bug" we found is that the Smarty Console (used to debug all the templates) was removed intentionally. 
 
/controllers/admin/AdminPerformanceController.php
 
On the initFieldsetSmarty() function we must add to the "fields_forms" variable the next code:


array(
 'type' => 'radio',
 'label' => $this->l('Smarty Console'),
 'name' => 'smarty_console',
 'values' => array(
   array(
    'id' => 'smarty_console_2',
    'value' => 2,
    'label' => $this->l('Always display'),
    'hint' => $this->l('This option should be used in a production environment.')
   ),
   array(
    'id' => 'smarty_console_1',
    'value' => 1,
    'label' => $this->l('Display through URL'),
    'hint' => $this->l('It should be used in a production environment when you need debug.')
   ),
   array(
    'id' => 'smarty_console_0',
    'value' => 0,
    'label' => $this->l('Never display'),
    'hint' => $this->l('Not display.')
   )
  )
    ),
    array(
  'type' => 'text',
  'label' => $this->l('Smarty Console Key'),
  'name' => 'smarty_console_key'
    )

On the same file, search for postProcess() function and near the line 650 aprox. that start with if ($this->tabAccess['edit'] === '1'). We can see how the function update two "config" variables, SMARTY_FORCE_COMPILE y el SMARTY_CACHE, but the two for the Smarty console are missing. On the next you can find the complete code block:
 

if ($this->tabAccess['edit'] === '1')
{
 Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', _PS_SMARTY_NO_COMPILE_));
 Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0));
 Configuration::updateValue('PS_SMARTY_CONSOLE_KEY',Tools::getValue('smarty_console_key','SMARTY_DEBUG'));
 Configuration::updateValue('PS_SMARTY_CONSOLE', Tools::getValue('smarty_console', 0));
 $redirectAdmin = true;
}

 
/config/smarty.config.inc.php
 
On this file we need to paste the next code block above the comment that says /* Use this constant if you want to load smarty without all PrestaShop functions */ near the 40th line.
 

// Production mode
$smarty->debugging = false;
$smarty->debugging_ctrl = 'NONE';
 
if (Configuration::get('PS_SMARTY_CONSOLE') == _PS_SMARTY_CONSOLE_OPEN_BY_URL_)
{
 $smarty->debugging_ctrl = 'URL';
 $smarty->smarty_debug_id = Configuration::get('PS_SMARTY_CONSOLE_KEY');
}
else if (Configuration::get('PS_SMARTY_CONSOLE') == _PS_SMARTY_CONSOLE_OPEN_)
 $smarty->debugging = true;

 
/tools/smarty/sysplugins/smarty_internal_templatebase.php
 
Search for the commentary // display or fetch that is near over 350 line, and change the conditional if($display), to the next code:
 

// display or fetch
if ($display || strpos($template->template_resource,'global.tpl')!==false) {

If we go back to the backoffice, we can see that the options are recovered.
lol2.png
 
One more thing. If we go throug "URL", once we put SMARTY_DEBUG (or what you decide), the system make a "cookie" that always open the Smarty Console. You can erase the cookie or put the next parameter on the URL: http://ourshop.com/?SMARTY_DEBUG=off

  • Like 8
Link to comment
Share on other sites

  • 1 month later...

... other way to active console

just use {debug} code for example in header.tpl file located in your theme

Sometimes i use that one, on a test shop and inside the tpl to check which variables are availble.

If on the real shop, i prefer the SMARTY_DEBUG option, this way won't show for all users, and it's easier.

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...

... other way to active console

just use {debug} code for example in header.tpl file located in your theme

This method doesn't show a pop up window like it used to do on previous PrestaShop versions; it just writes some difficult to read code into the HTML. I do the maintenance for several stores, and the dmartin_webimpacto system is too laborious for me.

 

Any idea for recovering the pop up window more easily?

Link to comment
Share on other sites

Thanks for the guide.

I still have one problem. Smarty_debug doesn't open a new window, only writes the variables at the bottom of the page.

 

same problem with {debug} in the template... anyone have an idea ?

Link to comment
Share on other sites

same problem with {debug} in the template... anyone have an idea ?

 

From http://forge.prestashop.com: Issue PS1.6  PSCSX-2651,30/7/2014, debug console writes directly in page

 

Mainly :

The popup window started working as expected when I toggled "Move Javascript to the end" to ON in BO > Advanced Parameters > Performance.

 

 

and 3 others minors changes written in the issue.

Edited by phili_b (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 5 months later...

Sometimes i use that one, on a test shop and inside the tpl to check which variables are availble.

If on the real shop, i prefer the SMARTY_DEBUG option, this way won't show for all users, and it's easier.

 

You can just {if isset($smarty.get.debug)}{debug}{/if} and in url add domain.com?debug

Edited by ircykk (see edit history)
Link to comment
Share on other sites

my theme doesn't work well with js at the end.

will try the commit to see if it works any way...

 

 

For me worked  taking into account another tpl so the script for the popup works fine

 

instead of

if ($display || strpos($template->template_resource,'global.tpl')!==false) {

For example

if ($display || strpos($template->template_resource,'blockmyaccountfooter.tpl')!==false) {

Edited by Enrique Gómez (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...