2018-03-17 13:50:04 +01:00
# tplBlock
2018-03-17 13:55:48 +01:00
2018-03-21 07:44:08 +01:00
A very simple PHP template class
2018-03-19 23:05:21 +01:00
[![Build Status ](https://travis-ci.org/gnieark/tplBlock.svg?branch=master )](https://travis-ci.org/gnieark/tplBlock)
2018-03-21 07:44:08 +01:00
# Sample
This simple template file:
```html
< 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 >
```
2018-03-21 07:46:45 +01:00
Parsed with this code:
2018-03-21 07:44:08 +01:00
```php
< ?php
2018-04-02 15:30:43 +02:00
require_once ("path/TplBlock.php");
2018-03-21 07:44:08 +01:00
//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
< 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.
2018-03-17 13:55:48 +01:00
2018-03-21 07:44:08 +01:00
If a block ( < --BEGIN . . . . ) is in the template , but is not called , it will be deleted .
2018-03-17 13:56:52 +01:00
2018-03-29 15:34:07 +02:00
For now, class is permissive. I'll improve it to manage templating errors.
2018-04-02 15:30:43 +02:00
# 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.