At first, create a class named SmartyRenderer under application/components or any directory you want.
<?php
class SmartyViewRenderer extends CApplicationComponent implements IViewRenderer
{
/**
* @var Smarty
*/
private $_smarty;
/**
* @var string
*/
public $fileExtension = '.html'; // or ".php" if you like
public function init()
{
$smartyPath = Yii::getPathOfAlias('application.vendors.smarty');
Yii::$classMap['Smarty'] = $smartyPath . '/Smarty.class.php';
Yii::$classMap['Smarty_Internal_Data'] = $smartyPath . '/sysplugins/smarty_internal_data.php';
$this->_smarty = new Smarty();
$this->_smarty->compile_dir = Yii::app()->getRuntimePath() . '/smarty/compile';
$this->_smarty->cache_dir = Yii::app()->getRuntimePath() . '/smarty/cache';
$this->_smarty->left_delimiter = '{{'; // chenge it if you want other delimiter
$this->_smarty->right_delimiter = '}}';
$this->_smarty->force_compile = true;
Yii::registerAutoloader('smartyAutoload');
}
public function renderFile($context, $file, $data, $return)
{
foreach ($data as $key => $value)
$this->_smarty->assign($key, $value);
$return = $this->_smarty->fetch($file);
if ($return)
return $return;
else
echo $return;
}
}
Then, put smarty under appliction/vendors.
Now, the smarty renderer has been setup.
enjoy it.
[zh-cn] [如何在 Yii 1.x 中使用 Smarty 3](http://dongbeta.com/post/1215 "http://dongbeta.com/post/1215")
Extension
Smarty renderer extension
I know the Smarty renderer extension
I know the Smarty renderer extension, But it couldn't work.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.