* move Twig functions to separate file

This commit is contained in:
slawkens 2018-05-29 18:14:21 +02:00
parent b714bf4abe
commit 6158d81b5e
2 changed files with 33 additions and 30 deletions

View File

@ -32,36 +32,7 @@ require_once SYSTEM . 'libs/cache.php';
$cache = Cache::getInstance($config['cache_engine'], $config['cache_prefix']);
// twig
require_once LIBS . 'Twig/Autoloader.php';
Twig_Autoloader::register();
$twig_loader = new Twig_Loader_Filesystem(SYSTEM . 'templates');
$twig = new Twig_Environment($twig_loader, array(
'cache' => CACHE . 'twig/',
'auto_reload' => true,
//'debug' => true
));
$function = new Twig_SimpleFunction('getStyle', function ($i) {
return getStyle($i);
});
$twig->addFunction($function);
$function = new Twig_SimpleFunction('getLink', function ($s) {
return getLink($s);
});
$twig->addFunction($function);
$function = new Twig_SimpleFunction('hook', function ($hook) {
global $hooks;
$hooks->trigger($hook);
});
$twig->addFunction($function);
$filter = new Twig_SimpleFilter('urlencode', function ($s) {
return urlencode($s);
});
$twig->addFilter($filter);
require_once SYSTEM . 'twig.php';
// trim values we receive
if(isset($_POST))

32
system/twig.php Normal file
View File

@ -0,0 +1,32 @@
<?php
require_once LIBS . 'Twig/Autoloader.php';
Twig_Autoloader::register();
$twig_loader = new Twig_Loader_Filesystem(SYSTEM . 'templates');
$twig = new Twig_Environment($twig_loader, array(
'cache' => CACHE . 'twig/',
'auto_reload' => true,
//'debug' => true
));
$function = new Twig_SimpleFunction('getStyle', function ($i) {
return getStyle($i);
});
$twig->addFunction($function);
$function = new Twig_SimpleFunction('getLink', function ($s) {
return getLink($s);
});
$twig->addFunction($function);
$function = new Twig_SimpleFunction('hook', function ($hook) {
global $hooks;
$hooks->trigger($hook);
});
$twig->addFunction($function);
$filter = new Twig_SimpleFilter('urlencode', function ($s) {
return urlencode($s);
});
$twig->addFilter($filter);