Add Twig support

Add basic support for Twig template engine

Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
Maurício Meneghini Fauth 2017-03-11 13:37:16 -03:00
parent a87108c96f
commit 00c74a2fcd
3 changed files with 27 additions and 2 deletions

2
.gitignore vendored
View File

@ -10,6 +10,8 @@
/tmp/
# For setup script
/config/
# Template cache
/templates/cache/
# ctags
tags
# Editor files

View File

@ -36,7 +36,8 @@
"phpmyadmin/motranslator": "^3.0",
"phpmyadmin/shapefile": "^2.0",
"phpseclib/phpseclib": "^2.0",
"google/recaptcha": "^1.1"
"google/recaptcha": "^1.1",
"twig/twig": "^2.2"
},
"conflict": {
"tecnickcom/tcpdf": "<6.2"

View File

@ -31,6 +31,16 @@ class Template
*/
protected $helperFunctions;
/**
* Twig loader
*/
protected $loader;
/**
* Twig environment
*/
protected $environment;
const BASE_PATH = 'templates/';
/**
@ -45,6 +55,10 @@ class Template
$this->name = $name;
$this->data = $data;
$this->helperFunctions = $helperFunctions;
$this->loader = new \Twig_Loader_Filesystem(static::BASE_PATH);
$this->environment = new \Twig_Environment($this->loader, array(
'cache' => static::BASE_PATH . 'cache',
));
}
/**
@ -139,7 +153,15 @@ class Template
*/
public function render($data = array(), $helperFunctions = array())
{
$template = static::BASE_PATH . $this->name . '.phtml';
$template = static::BASE_PATH . $this->name;
if (file_exists($template . '.twig')) {
$this->set($data);
return $this->environment->load($this->name . '.twig')
->render($this->data);
}
$template = $template . '.phtml';
try {
$this->set($data);
$this->helperFunctions = array_merge(