Assuming you’re using the method demonstrated in the Zend Framework Manual, the first thing you need is to configure the Zend AutoLoader. Add this to the index.php file in your public directory:

// Configure autoloader
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();

// Require Smarty Engine
require_once 'Smarty/Smarty.class.php'; // Assuming that you have the Smarty engine at "library/Smarty"
$autoloader->pushAutoloader('Smarty', 'smartyAutoload');

Change the following line in “Smarty/Smarty.class.php” (about line 91) from this:

if (set_include_path(SMARTY_SYSPLUGINS_DIR . PATH_SEPARATOR . get_include_path()) !== false) {

To this:

if (!class_exists('Zend_Loader_Autoloader') && set_include_path(SMARTY_SYSPLUGINS_DIR . PATH_SEPARATOR . get_include_path()) !== false) {

Next, comment out the line in the Smarty Constructor (about line 237):

//$this->template_dir = array('.' . DS . 'templates' . DS);

We want to keep it a null value (which is the default). If we don’t make this change in the constructor (mentioned just above), we’ll get PHP Notices that Zend_Controller_Action_Helper_ViewRenderer tried to convert an array to a string.

Finally, add this to your bootstrapper class:

protected function _initView()
{
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(‘ViewRenderer’);
$view = new Zend_View_Smarty();

$viewRenderer->setView($view)
->setViewScriptPathSpec(APPLICATION_PATH . ‘/views/scripts/:controller/:action.:suffix’)
->setViewSuffix(‘tpl’);
}

If you’re using modules, you might want to make a slight change to the setViewScriptPathSpec method:

setViewScriptPathSpec(APPLICATION_PATH . ‘/modules/:module/views/scripts/:controller/:action.:suffix’);

You should be good to go. I should mention that this will cause your layouts to be parsed via Smarty as well; which presents its own problems. A potential work around is to include a common header and footer for each individual template, although this is far from ideal. In that case, what you might want to do is disable the view renderer’s auto render feature and create a custom plugin or action helper that will render the templates and layouts. I’m considering expounding on this in another post…