RainTPL
PHP Template engine, compile HTML template to PHP programmed 'www.raintpl.com'Features
- Quikly: load precompiled template.
- Easy: 2 files, 7 tags and 3 methods for design template.
Installation
copy the files raintpl.class.php and raintplcompiler.class.php in project include directory (ex. includes), you must create a templates directory (ex. themes), include in your php script the raintpl.class.php file.include Rain TPL
include( 'includes/raintpl.class.php' ); $tpl = new RainTPL( 'your themes file' );
How To use it?
The best features of the RainTPL that is easy to use.RainTPL tags:
- {$variablename}
- If...Else Statements
- Loop
- {include="file"}
- {ignore}
- {noparse}
- {#constant name#}
{$variable name}
Variable are the dynamic contents of template, valorized in the execution of script with method RainTPL::assign().Variable name is case sensitive. Example#1:My Age is: {$age}You can use arithmetics operator for simple operations: +, -, *, /, %
Example#2:My Age is: {$age+5}
one of the best Feature
You can assign functions to variables, with next syntax:{$var|function_name:par_1,par_2}#Example{$text|substr:0,10}
tip: {$counter}, {$key} e {$value} are reserved variables, take special value inside a loop.
Other reserver variables are: {$GLOBALS}, {$_GET}, {$_POST}, {$_COOKIES}, {$_SESSION} e {$_SERVER}.
If...Else Statements
{if condition="condition"}{elseif condition="condition"}{else}{/if}
#Tip: In "condition" use variables without comma "{", "}", and use regular PHP code.
Example#1:
{if condition="$year > 18"}major{/if}
{if condition="$year > 18"}major{else}not major{/if}
{if condition="$year < 20"}
less than 20 years
{elseif condition="$year < 30"}
less than 30 years
{/if}
Loop
{loop name="loop name"}{/loop}This tag allow to read array and object in a loop. Betweein {loop} and {/loop} you can use special variables:{$key}, key of the array element{$value}, value of the array.{$counter}, loop counter. Start from 0, if you want to start from other number use +n, ex. {$counter+1}
Example#1:
PHP:$user = array( 0 => array( 'name'=>'jooria', 'age'=>19 ), 1 => array( 'name'=>'Federico', 'age'=>27 ), 2 => array( 'name'=>'Giovanna', 'age'=>32 ) ); $tpl->assign( "user", $user ); echo $tpl->draw( 'Template' );Template:
{loop name="user"}
#{$counter+1} {$value.name} His Age {$value.age}
{/loop}Output:#1 jooria His Age 19 #2 Federico His Age 27 #3 Giovanna His Age 32Example#2:Loop With Mysql DataBase. PHP:
$sql = mysql_query("SELECT * FROM users limit 5");
while ($Row = mysql_fetch_array($sql))
{
$user[] = array('name'=>$Row['name'],'age'=>$Row['age'],);
}
$tpl->assign( "user", $user );
The Template:is the same as the previous example{include="file"}
Includes HTML template files.Example#1: {include="menu"}
with variable path:
{include="$style/$tpl"}
include sub tpl folder:
{include="folder/folder/tpl"}
ignore and noparse
{noparse}{/noparse} All between {noparse} and {/noparse} will not be compiled. Example#1:
{$variable}
{loop name="news"}{$value.title}{/loop}
{noparse}
{$variable}
{loop name="news"}{$value.title}{/loop}
{/noparse}
{ignore}{/ignore}
All between tags {ignore} and {/ignore} is deleted in the compiled file.
Example#1:{ignore}dolor sit amet{/ignore}
{#constant name#}
You can read defined constant with tag {#constant_name#}. Example#1:define( 'THEME', 'default' );and tpl
{#THEME#}
function path_replace();
this function in raintpl.compile.class.php in line 327. path_replace is a default function, if you don't want automatic change for the attributes:"<img src"," <td background" and "<a href"just use the # in the url example:
<img src="images/foto.jpg#">or use the full url
<img src="http://www.jooria.com/images/foto.jpg">
Free Exclusive And High Quality PSD Photoshop Resource For Web Design
