Skip to content

Commit 1202edb

Browse files
committed
Now you can override any Twig Environment Options
1 parent 0f0211a commit 1202edb

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

libraries/Twig.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,22 @@
1616

1717
class Twig
1818
{
19+
/**
20+
* @var array Twig Environment Options
21+
*/
1922
private $config = [];
2023

24+
/**
25+
* @var array Functions to add to Twig
26+
*/
2127
private $functions_asis = [
2228
'base_url', 'site_url',
2329
];
30+
31+
/**
32+
* @var array Functions with `is_safe` option
33+
* @see http://twig.sensiolabs.org/doc/advanced.html#automatic-escaping
34+
*/
2435
private $functions_safe = [
2536
'form_open', 'form_close', 'form_error', 'form_hidden', 'set_value',
2637
];
@@ -44,8 +55,10 @@ public function __construct($params = [])
4455
{
4556
// default config
4657
$this->config = [
47-
'paths' => [VIEWPATH],
48-
'cache' => APPPATH . 'cache/twig',
58+
'paths' => [VIEWPATH],
59+
'cache' => APPPATH . 'cache/twig',
60+
'debug' => ENVIRONMENT !== 'production',
61+
'autoescape' => TRUE,
4962
];
5063

5164
$this->config = array_merge($this->config, $params);
@@ -80,27 +93,14 @@ protected function createTwig()
8093
return;
8194
}
8295

83-
if (ENVIRONMENT === 'production')
84-
{
85-
$debug = FALSE;
86-
}
87-
else
88-
{
89-
$debug = TRUE;
90-
}
91-
9296
if ($this->loader === null)
9397
{
9498
$this->loader = new \Twig_Loader_Filesystem($this->config['paths']);
9599
}
96100

97-
$twig = new \Twig_Environment($this->loader, [
98-
'cache' => $this->config['cache'],
99-
'debug' => $debug,
100-
'autoescape' => TRUE,
101-
]);
101+
$twig = new \Twig_Environment($this->loader, $this->config);
102102

103-
if ($debug)
103+
if ($this->config['debug'])
104104
{
105105
$twig->addExtension(new \Twig_Extension_Debug());
106106
}

0 commit comments

Comments
 (0)