Note: Latest release and documentation are available at extension github page.
This extension allows you to use Smarty version 2 or 3 templates in Yii.
Resources ¶
Requirements ¶
- Yii 1.0 or above
Installation ¶
- Extract the release file under
protected/extensions
. - Download and extract
libs
folder contents of Smarty package underprotected/vendors/Smarty
. - Add the following to your config file 'components' section:
'viewRenderer'=>array(
'class'=>'application.extensions.yiiext.renderers.smarty.ESmartyViewRenderer',
'fileExtension' => '.tpl',
//'pluginsDir' => 'application.smartyPlugins',
//'configDir' => 'application.smartyConfig',
),
Usage ¶
- Smarty documentation.
- Current controller properties are accessible via {$this->pageTitle}.
- Yii properties are available as follows: {$Yii->theme->baseUrl}.
- Used memory is stored in {$MEMORY}, used time is in {$TIME}.
Change Log ¶
1.0.1 (available from github) ¶
- Smarty 3.1 compatibility (Sam Dark)
1.0.0 ¶
- changed autoload handling to work also when Yii autoloader has been modified (cebe)
- ensure Smarty does not use SMARTY_SPL_AUTOLOAD (cebe)
0.9.9 ¶
- Added possiblity to configure smarty properties (CAUTION: behavior of $filePermission changed) (cebe)
- Fixed issue with rendering Widgets within a template (cebe)
0.9.8 ¶
- Fixed renderFile method (Sam Dark)
- Fixed bug with autoload Smarty 3 files in *nix (maksimgrib)
0.9.7 ¶
- Code cleanup and minor fixes.
0.9.6 ¶
- Changed translation category to 'yiiext'.
- New naming conventions.
- readme_ru.
- Added $Yii variable.
0.9.5 ¶
- YiiExt naming conventions changed, see readme.
- Smarty 3 comatibility.
- t and link plugin functions.
0.9 ¶
- Initial public release (Sam Dark)
how about Dwoo
i think dwoo is a better choice
0.9.9 needs Smarty 3
Since 0.9.9 this extension will only work with Smarty 3.
You have to update to Smarty 3 or stay with Smarty 2 and 0.9.8.
There are also some issues with some Smarty 3 release candidates, so you should use Smarty 3.0.8 or higher.
how to use {extends}?
How to extend templates using {extends} syntax?
When I try to use {extends file="view.tpl"} it cannot find the file. When I use {extends file="{$smarty.current_dir}/view.tpl"} it doesn't work because of the following error: "[...]a variable file attribute is illegal"
Current template and "view.tpl" are in the same directory.
The problem exists if Smarty was previously used to render a file in another directory.
Workaround: add this code to renderFile function body:
$this->smarty->template_dir = dirname($sourceFile)
fix
i get error when loading. my fix is in file ESmartyViewRenderer.php from line 109 till 112
i think we should replace :
$this->smarty->plugins_dir[] = Yii::getPathOfAlias('application.extensions.Smarty.plugins'); if(!empty($this->pluginsDir)){ $this->smarty->plugins_dir[] = Yii::getPathOfAlias($this->pluginsDir); }
with
$this->smarty->addPluginsDir(Yii::getPathOfAlias('application.extensions.Smarty.plugins')); if(!empty($this->pluginsDir)){ $this->smarty->addPluginsDir(Yii::getPathOfAlias($this->pluginsDir)); }
scince there is setter and getter in Smarty and will issue error now.
my smarty version (in vendors folder) is 3.1.4
thank you.
fixed
@andr2k: just created an issue for you: https://github.com/yiiext/smarty-renderer/issues/4
@muaid: this has just been fixed in version 1.0.1, you can download it from github: https://github.com/yiiext/smarty-renderer/tags
Using widgets
Hi,
how do I use widgets?
I tired it:
{$this->widget('zii.widgets.CDetailView', array( 'data'=>$model, 'attributes'=>array( 'id', 'url' ) ))}
widgets
In Smarty there is a different syntax for arrays with []. You also have to return rendered content (3rd parameter true).
example:
{$this->widget('zii.widgets.CDetailView', [ 'data'=>$model, 'attributes'=>[ 'id', 'url' ] ], true)}
Re: widgets
Thank you!
Error on github page.
Getting
Fatal error: Cannot use object of type stdClass as array in /var/lib/jenkins/workspace/yiiext.github.com/app/components/YiiextGithubApi.php on line 72
on the 'extension github page' (http://yiiext.github.com/extensions/smarty-renderer/index.html) for about the last week. Would really like to look at this!
website is fixed now.
http://yiiext.github.com/extensions/smarty-renderer/index.html
add to included path
Remenber to add the 'application.vendors.*' to application config import array
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.