smarty-renderer

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

  • Owner: yiiext/smarty-renderer
  • Platform:
  • License::
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Smarty view renderer

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

Resources

Requirements

  • Yii 1.0 or above
  • Smarty 3.0.6 or above

Installation

  • 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:
<?php
// ...
'viewRenderer'=>array(
  'class'=>'application.vendor.smarty.ESmartyViewRenderer',
    'fileExtension' => '.tpl',
    //'pluginsDir' => 'application.smartyPlugins',
    //'configDir' => 'application.smartyConfig',
    //'prefilters' => array(array('MyClass','filterMethod')),
    //'postfilters' => array(),
    //'config'=>array(
    //    'force_compile' => YII_DEBUG,
    //   ... any Smarty object parameter
    //)
),

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

Usage

  • 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="path.to.widget.Class"} 

	{*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 *}
        	{$widget->some_widget_method_or_variable} 
  	{/begin_widget} 
  • 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])}
   {/form} 
  • 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"}

Main metrics

Overview
Name With Owneryiiext/smarty-renderer
Primary LanguagePHP
Program languagePHP (Language Count: 1)
Platform
License:
所有者活动
Created At2011-08-18 20:42:34
Pushed At2018-01-29 12:56:10
Last Commit At2018-01-29 19:56:09
Release Count8
Last Release Namev1.0.7 (Posted on )
First Release Name1.0.0 (Posted on 2011-11-03 14:52:49)
用户参与
Stargazers Count49
Watchers Count10
Fork Count27
Commits Count80
Has Issues Enabled
Issues Count15
Issue Open Count2
Pull Requests Count13
Pull Requests Open Count4
Pull Requests Close Count5
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private