Enable Smarty Debug Console with CakePHP

Smarty is a great templating engine. I decided to use Smart with my CakePHP application.

To integrate Smarty with CakePHP, I following the instructions by tclineks: http://is.gd/iiZD68. Then, I implemented the blog tutorial application using Smarty. Unfortunately, I found that working with Smarty without the Smarty Debug Console was inefficient. Here are the steps that I followed to enable Smarty Debug Console:

1. In the function display_debug($obj) of class  Smarty_Internal_Debug, modify

echo $_template->getRenderedTemplate();
$smarty->left_delimiter = $ldelim;
$smarty->right_delimiter = $rdelim;


//echo $_template->getRenderedTemplate();
$debugStuff = $_template->getRenderedTemplate();
$smarty->left_delimiter = $ldelim;
$smarty->right_delimiter = $rdelim;
return $debugStuff;

2. In SmartyView.php add the following method to the class SmartyView:

function renderLayout($content_for_layout, $layout = null) {
  $layoutRender = parent::renderLayout($content_for_layout, $layout);
  $smartyDebug = Smarty_Internal_Debug::display_debug($this->Smarty);
  return $layoutRender . $smartyDebug;

3. Make sure that you have debug.tpl in vendor/smarty folder.

4. In Smarty.class.php, change

public $debug_tpl = null;


public $debug_tpl = SMARTY_DIR;

5. Comment out the following line in smarty_internal_debug.php

//$_template->assign('assigned_vars', $_assigned_vars); 

The reason we need to comment out the above line is because it will generate too many nested variables. Smarty will report an error and stop rendering. If someone knows a way to overcome this problem, kindly share that with me. My quick resolution for the time being is to disable this line.

6. In SmartyView contructor, add the following line:

$this->Smarty->debugging  = true;

Now, your Smarty Debug Console will show up.

Enjoy Smarty with CakePHP!

Smarty Debug Console


This entry was posted in CakePHP, Debugging, Smarty Templating Engine. Bookmark the permalink.

Leave a Reply