Methods

php tpleng ( [string $root [, string $empty]] )
 

root ( default: './' ) - root directory of templates

empty ( default: 'empty' ) - defines how uknown handles should be replaced if not declared

'empty' - remove
'none' - keep
'comment' - comment
'space' - change into  


php Template Engine initialization
  require_once('./tpleng.class.php');
$tpleng = new tpleng('templates/', 'comment');

php set_file ( string $var_name, string $file_name )
 

var_name - var's handle which should be assigned to

file_name - file name


php main template file
 

$tpleng->set_file('template', 'template.htm');

sets main template file


php files only with blocks
 

$tpleng->set_file('temporary', 'blocks1.htm');
$tpleng->set_file('temporary', 'blocks2.htm');

sets file with blocks. If the file contains only block those files may be assigned on the same handle.


php set_var ( string $var_name, string $var_value )
 

var_name - var's handle which should be assigned to

var_value - handle's value


php simple handle
 

$tpleng->set_var('name', 'Bart');

assign simple handle


html simple handle
 

{name}

handles must be written between braceleft ('{') and braceright ('}')


php handle-array
 

data could be array as well

$person= array(
            
'name' => 'Bart',
            
'surname' => 'Simpson',
            
'passports' => array(
                        
'code' => '666',
                        
'serialno' => '999'));
$tpleng->set_var('persons', $person);


html handle-array
 

{persons.name}, {persons.surname}, {persons.passports.code}, {persons.passports.serialno}

handle-array's must be declared the same as simple handles but handle and subhandle should be separated with dot.


php ifset tag
 

first example

$person= array(
            
'name' => 'Bart',
            
'surname' => 'Simpson',
            
'email' => 'bart@springfield.cc');
$tpleng->set_var('persons', $person);

second example

$person= array(
            
'name' => 'Bart',
            
'name' => 'Simpson');
$tpleng->set_var('persons', $person);


html ifset tag
 

<tpl ifset="persons.email"><a href="mailto:{persons.email}"></tpl ifset="persons.email">
{persons.name} {persons.surname}
<tpl ifset="persons.email"></a></tpl ifset="persons.email">

you may use <tpl ifset="var_name"> tag. If the handle is set, text in this tag will be written, else will be deleted

the first example's result:

Bart Simpson

second example's result:

Bart Simpson


php set_loop ( string $loop_name, array $loop_value )
 

loop_name - loop's handle which should be assigned to

loop_value - loop's values


php simple loop
  $loop = array(
    array(
'name' => 'Bart', 'surname' => 'Simpson'),
    array(
'name'=> 'Selma', 'surname'=> 'Bouvier'),
    array(
'name'=> 'Waylon', 'surname'=> 'Smithers'));

$tpleng->set_loop('list', $loop);

html simple loop
 

<table>
    <tpl loop="list">
    <tr>
        <td>{list.name}</td>
        <td>{list.surname}</td>
    </tr>
    </tpl loop="list">
    <tr>
        <td>there are no people in the list</td>
    </tr>
    </tpl noloop="list">
</table>

loop should be declared between <tpl loop="loop_name"> and </tpl loop="loop_name"> tags. There may be </tpl noloop="loop_name"> tag also. Structure should be like this:

<tpl loop="loop_name">
loop content
</tpl loop="loop_name">
text which will be shown if loop array is empty
</tpl noloop="loop_name">

variables should be declared like this: {loop_name.var_name}


php loop and ifset tag
  $loop = array(
    array(
'name' => 'Bart', 'surname' => 'Simpson', 'email' => 'bart@springfield.cc'),
    array(
'name'=> 'Selma', 'surname'=> 'Bouvier'),
    array(
'name'=> 'Waylon', 'surname'=> 'Smithers', 'email' => 'waylon@springfield.cc'));

$tpleng->set_loop('list', $loop);

html loop and ifset tag
 

<table>
    <tpl loop="list">
    <tr>
        <td>
            <tpl ifset="list.email">
                <a href="mailto:{list.email}">
            </tpl ifset="list.email">
            {list.name}
            <tpl ifset="list.email">
                </a>
            </tpl ifset="list.email">
        </td>
        <td>
            {list.surname}
        </td>
    </tr>
    </tpl loop="list">
</table>

will be generated list where people (who have emails) names' will be links to email them and there won't be empty links


php set_rotation ( string $loop_name, string $rot_name, array $rot_value )
 

loop_name - name of loop in which rotation is active

rot_name - rotation handle in loop

rot_value - rotation values


php rotation in loop
 

$colors = array('#FFFFFF', '#F9F9F9');
$tpleng->set_rotation('list', 'color', $colors);

for example if you need to make table where rows should be different color.
(using example above)


html rotation in loop
 

<table>
    <tpl loop="list">
    <tr bgcolor="{list.color}">
        <td>
            <tpl ifset="list.email">
                <a href="mailto:{list.email}">
            </tpl ifset="list.email">
            {list.name}
            <tpl ifset="list.email">
                </a>
            </tpl ifset="list.email">
        </td>
        <td>
            {list.surname}
        </td>
    </tr>
    </tpl loop="list">
</table>

every other row will be light grey.


php set_block ( string $var_name, string $block_name [, string $append] )
 

var_name - handle which should be assigned to

block_name - handle of the block which content should be assigned

append ( default: false ) - if value is true, then content of the block will be append to handle else content will be assign.


php simple block
  $tpleng->set_file('blocks', 'bloks.htm');
$tpleng->set_block('text_a', 'block_a');
$tpleng->set_block('text_b', 'block_b');
$tpleng->parse('blocks');

html simple block (blocks.htm)
 

boo
<tpl block="block_a">
this is text in A
</tpl block="block_a">

<tpl block="block_b">
this is text in B
{text_a}
this is also text in B
</tpl block="block_b">
foo
{text_b}

result:

boo


foo

this is text in B

this is text in A

this is also text in B


php parse ( string $var_name [, string $output [, string $file_name]] )
 

var_name - handle which should be parsed

output ( default: 'echo' ) - output destination

'echo' - echo text
'return' - return as the result of the function
'file' - writes into file

file_name ( default: 'output.htm' ) - file name where content should be written. It is active only if output is set to 'file'


php parsing into file
 

Simply prints content of the handle called 'main'

$tpleng->parse('main');