You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2.3 KiB


A very simple PHP template class

Build Status


This simple template file:

    <!-- BEGIN templatesystem -->
        <li><a href="{{templatesystem.url}}"> {{}}</a>
         by {{}} is {{templatesystem.quality}}</li> 
    <!-- END templatesystem -->


Parsed with this code:

require_once ("path/TplBlock.php");

//init object
$tpl = new TplBlock();
//add a var
$tpl->add_vars(array("pageTilte" => "Poke @zigazou ;)"));

$data = array(
        "url"       => "",
        "name"      => "tplBlock",
        "author"    => "Gnieark",
        "quality"   => "simple and perfect"
        "url"       => "",
        "name"      =>  "TemplateEngine",
        "author"    => "Zigazou",
        "quality"   => "more complex than tplBlock"


//add blocks
foreach ($data as $block){
    $tplTemplateSystem = new TplBlock("templatesystem");
    $tplTemplateSystem -> add_vars($block);

echo $tpl->apply_tpl_file("template.html");

will return:

    <h1>Poke @zigazou ;)</h1>
            <li><a href=""> tplBlock</a>
         by Gnieark is simple and perfect</li> 
            <li><a href=""> TemplateEngine</a>
         by Zigazou is more complex than tplBlock</li> 


Conception choices

I wrote this class for use it on others personnals projects. It's really simple. I think logicals functions "OR" "IF", filtering, caching, are not the templating system matter.

If a block ( <--BEGIN .... )is in the template, but is not called, it will be deleted.

For now, class is permissive. I'll improve it to manage templating errors.


Use composer etc... or simply put the file TplBlock.php on your project


See the comments on the TplBlock.php file.