Rain TPL Yii View Renderer
The easy and fast template engine for PHP. Rain.TPL makes application easier to create & enables designers/developers to work better together.
Project Page
Download
Documentation
Speed Test
Github Project Page
Yii Extension Github Project Page
Requirements
- PHP 5
- Yii 1.1.10 (Tested on 1.1.10 but should work on older versions as well)
Installation
1. Download or Clone the files
2. Extract into the extensions folder
3. Edit the application config file and add the following array under the ‘components’ array:
'viewRenderer'=>array( 'class'=>'application.extensions.RainTPLViewRenderer', ),
Configure
The available options you can set for this view renderer are:
'viewRenderer'=>array( 'class'=>'application.extensions.RainTPLViewRenderer', // File extension used for views 'fileExtension' => '.tpl', // is the template directory 'tpl_dir' => null, // where it save compiled templates and cache 'cache_dir' => null, // the absolute base url of your application (eg. http://www.raintpl.com) 'base_url' => null, // enable/disable the path replace 'path_replace' => false, // configure what to replace 'path_replace_list' => array(), // configure what command are not allowed 'black_list' => array(), // enable/disable the control if template was modified by the last compiling 'check_template_update' => true, // enable/disable the use of php tags in your template 'php_enabled' => false, // Use the latest beta version for rain tpl 3 'useRainBeta' => false, // Will not cache templates 'debug' => false, // Auto escape variables 'auto_escape' => false, ),
Usage
To render a view you would call the render method the same way
——————
$this->render('someview', $params);
Template Syntax Examples
| PHP | Rain TPL |
| <?php echo $var; ?> | {$var} |
| <?php echo CONSTANT; ?> | {#CONSTANT#} |
| <?php $num + 10; ?> | {$num + 10} |
| <?php echo $website['name']; ?> | {$website.name} |
| <?php echo $GLOBALS['name']; ?> | {$GLOBALS.name} |
| <?php if($year > 18) {echo ‘major’;}?> | {if=”$year > 18″}major{/if} |
| <?php if($year > 18) {echo ‘major’;} else {echo ‘not major’;}?> | {if=”$year > 18″}major{else}not major{/if} |
| <?php if() {echo ‘Hello’ . $name} else{ echo ‘Not Logged’; } ?> | {if=”isLogged()”}Hello {$name}{else}Not Logged{/if} |
| <?php echo $is_logged ? ‘Hellow’ . $name : ‘Not logged’; ?> | {$is_logged? ‘Hello $name’:'Not logged’} |
| <?php foreach($user_list as $key => $value) {echo $key . ‘-’ . $value['name'] . ‘ ‘}?> |
{loop=”user_list”} {$key} – {$value.name} {/loop} |
| <?php include ‘footer’; ?> | {include=”footer”} |
| <?php echo cut_html($news, 0, 12); ?> | {$news|cut_html:0,12} |
| <?php pagination( $selected_page, NEWS_PER_PAGE, URL ); ?> | {function=”pagination( $selected_page, NEWS_PER_PAGE, URL )”} |
| <?php echo substr($string,0,5); ?> | {function=”substr($string,0,5)”} |
| <?php /* comment */ ?> | {* comment *} |
For more info see [Documentation](http://www.raintpl.com/Documentation/)
Authors
Vincent Gabriel
Does your Yii extension for Rain Tpl work with the new Rain Beta 3?
Can you use the Yii caching with Rain TPL or do you have to use the Rain cache capability and turn all other caching off in Yii?
Thanks
Gordon
Yes, It supports Rain TPL Beta 3 see:
// Use the latest beta version for rain tpl 3
‘useRainBeta’ => false, // set to true to use rain tpl beta 3
It will use the default rain tpl cache option not the one you use with your Yii application. But you don’t need to turn Yii cache off.
Rain TPL Ver 3 Cache is Deprecated:
I understand your post and answer thank you, but have you seen this support link that says Rain TPL 3 has deprecated cache?
See link:
http://www.raintpl.com/Forum/Development-Forum/Rain-TPL-3/?t=211
They are saying you will need to use APC or other for cache now. Have you tested the Rain TPL 3 cache with Yii? I am not sure what to do with cache and Yii now and Rain TPL beta 3.
Thanks
Gordon
I haven’t seen that up until now, So i’m not sure. I did test the Rain TPL 3 class and it works just fine with Yii. Although i didn’t include or incorporate any cache mechanism, So you’ll have to do it yourself if rain tpl does not support it in 3 beta.
I write
$this->render('index',array('val'=>'testing' );in a controller, however I cant display it using {val} . It work fine using php syntax. Thanks!** {$val}
Hmm i’m not sure why this won’t work but to debug this try looking at the cache file that was cached and see what exactly is placed instead of that {$var} variable.
I am trying to install it and I get an exception:
Property “CWebApplication.viewRenderer” is read only.
What I am doing wrong?
what version of Yii are you using?