1
0
Fork 0
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
Gnieark 119485f334 test travis vor 6 Jahren
sample addSubBlocsDefinitions vor 6 Jahren
test addSubBlocsDefinitions vor 6 Jahren
.gitignore gitignore vor 6 Jahren
.travis.yml test travis vor 6 Jahren
Makefile Source code now conforms to PSR-2 vor 6 Jahren
README.md improve Readme vor 6 Jahren
TplBlock.php hhvm vor 6 Jahren
autoload.php Trying with a custom autoload.php vor 6 Jahren
composer.json Trying with PHPUnit v5.7 vor 6 Jahren
composer.lock permit fun with spaces vor 6 Jahren
phpcs.xml Source code now conforms to PSR-2 vor 6 Jahren
phpmd.xml Source code now conforms to PSR-2 vor 6 Jahren

README.md

tplBlock

A very simple PHP template class

Build Status

Sample

This simple template file:

<html>
<body>
    <h1>{{pageTilte}}</h1>
    <ul>
    <!-- BEGIN templatesystem -->
        <li><a href="{{templatesystem.url}}"> {{templatesystem.name}}</a>
         by {{templatesystem.author}} is {{templatesystem.quality}}</li> 
    <!-- END templatesystem -->
    </ul>

</body>
</html>

Parsed with this code:

<?php
require_once ("path/TplBlock.php");

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


$data = array(
    array(
        "url"       => "https://github.com/gnieark/tplBlock",
        "name"      => "tplBlock",
        "author"    => "Gnieark",
        "quality"   => "simple and perfect"
    ),
    array(
        "url"       => "https://github.com/Zigazou/TemplateEngine",
        "name"      =>  "TemplateEngine",
        "author"    => "Zigazou",
        "quality"   => "more complex than tplBlock"

    )
);

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

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

will return:

<html>
<body>
    <h1>Poke @zigazou ;)</h1>
    <ul>
            <li><a href="https://github.com/gnieark/tplBlock"> tplBlock</a>
         by Gnieark is simple and perfect</li> 
            <li><a href="https://github.com/Zigazou/TemplateEngine"> TemplateEngine</a>
         by Zigazou is more complex than tplBlock</li> 
    
    </ul>

</body>
</html>

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.

Install

Use composer etc... or simply put the file TplBlock.php on your project https://raw.githubusercontent.com/gnieark/tplBlock/master/TplBlock.php

Documentation

See the comments on the TplBlock.php file.