This extension allows you to use Smarty 3 templates in Yii.
Clone or download
Latest commit c327516 Jan 29, 2018

Smarty view renderer

This extension allows you to use Smarty version 3 templates in Yii.



  • Yii 1.0 or above
  • Smarty 3.0.6 or above


  • Extract the release file under vendor/Smarty.
  • Download and extract libs folder contents of Smarty package under protected/vendor/Smarty.
  • Move files from plugins folder to protected/vendor/Smarty/plugins.
  • Add the following to your config file 'components' section:
// ...
    'fileExtension' => '.tpl',
    //'pluginsDir' => 'application.smartyPlugins',
    //'configDir' => 'application.smartyConfig',
    //'prefilters' => array(array('MyClass','filterMethod')),
    //'postfilters' => array(),
    //    'force_compile' => YII_DEBUG,
    //   ... any Smarty object parameter

There are some more options on configuring Smarty properties now. Will add documentation soon.


  • Smarty documentation.
  • You can use Yii aliases for including files inside the template. For example:
	You have to set path without extension
	{extends file="application.views.layout.main"} 
	{include file="application.views.controller._form"}
	Also you can use regular Smarty syntax for file path wich relative to current `views` directory:
	{include file="controller/_form.tpl"}
  • Current controller properties are accessible via {$this->pageTitle}.
  • Yii properties are available as follows: {Yii::app()->theme->baseUrl}.
  • Used memory is stored in {$MEMORY}, used time is in {$TIME}.

Smarty Plugins

  • widget and begin_widget plugins allow use Yii widgets in this way:
	{*Render widget without params*}
	{widget name=""} 

	{*You can set params by passing it in the widget-function*}
	{widget name="Breadcrumbs" links=['Library'=>'#', 'Data'] someParam="someValue"}
 	{*Another syntax. *}
	{begin_widget name="bootstrap.widgets.TbModal" id='anotherModalDialog' options=[backdrop=>static] otherParam="value" [...]}
        	{*Widget object are accessible via {$widget} variable inside the block *}
  • Form plugin is a syntax-sugar plugin for Yii ActiveForm. Syntax:
   {form name="product_form" id='form' type='horizontal' otherParam="value" [...]}
		{*Form object are accessible via variable with name equal to form name*}
        {$product_form->textFieldRow($this->model, 'name', ['class'=>'span5','maxlength'=>255])}
  • t() function allows to translate strings using Yii::t(). Syntax:
  {t text="text to translate" cat="app"}
  {t text="text to translate" cat="app" src="en" lang="ru"}
  {t text="text to translate" cat="app" params=$params}
  • link function allows to generate links using CHtml::link(). Syntax:
  {link text="test"}
  {link text="test" url="controller/action?param=value"}
  {link text="test" url="/absolute/url"}
  {link text="test" url="http://host/absolute/url"}