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.
Download
Go To Download The Last version
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:
Now I will explain in detail all of the tags
{$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: <a>{$age}</a>
You can use arithmetics operator for simple operations: +, -, *, /, %
Example#2:
My Age is: <a>{$age+5}</a>
one of the best Feature
You can assign functions to variables, with next syntax:.
{$var|function_name:par_1,par_2}#Examples
{$text|substr:0,10}
{$text|text_limit:10}
Nota: {$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:
<!-- year = 26 -->
{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:
The PHP file
$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' );
The Template:
{loop name="user"}
<p>#{$counter+1} <a>{$value.name}</a> His Age {$value.age}</p>
{/loop}
Output:
#1 jooria His Age 19
#2 Federico His Age 27
#3 Giovanna His Age 32
Example#2:
Loop With Mysql Data Bass.
The PHP file
$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"}ignore and noparse
{noparse}{/noparse}
All between {noparse} and {/noparse}will not be compiled.
Example#1:
<!-- this will be compiled-->
{$variable}
<img src="images/rtpl.gif">
{loop name="news"}{$value.title}{/loop}
{noparse}
<!-- this not will be compiled-->
{$variable}
<img src="images/rtpl.gif">
{loop name="news"}{$value.title}{/loop}
{/noparse}
{ignore}{/ignore}
All between tags {ignore} and {/ignore} is deleted in the compiled file.
Example#1:
<!-- will be ignored in the compiled file-->
{ignore}
dolor sit amet
{/ignore}
{#constant name#}
You can read defined constant with tag {#constant_name#}.
Example#1:
define( 'THEME', 'default' );{#THEME#}#tip: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#">
