Skip to content

Commit baf4f9d

Browse files
committed
Change config key functions_asis to function and add documentation
1 parent a9c65eb commit baf4f9d

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Remove comment marks below and fix the path for `Autoloader.php`:
7171
$this->load->library('twig');
7272
~~~
7373

74-
You can override the default configration:
74+
You can override the default configuration:
7575

7676
~~~php
7777
$config = [
@@ -126,6 +126,20 @@ $twig = $this->twig->getTwig();
126126

127127
Some helpers are added the functionality of auto-escaping for security.
128128

129+
### Adding Your Functions
130+
131+
You can add your functions with configuration:
132+
133+
~~~php
134+
$config = [
135+
'functions' => ['my_helper'],
136+
'functions_safe' => ['my_safe_helper'],
137+
];
138+
$this->load->library('twig', $config);
139+
~~~
140+
141+
If your filter explicitly outputs HTML code, you will want the raw output to be printed. In such a case, use `functions_safe`, and you have to make sure the output of the function is XSS free.
142+
129143
### Reference
130144

131145
#### Documentation

libraries/Twig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public function __construct($params = [])
5050

5151
$this->config = array_merge($this->config, $params);
5252

53-
if (isset($params['functions_asis']))
53+
if (isset($params['functions']))
5454
{
5555
$this->functions_asis =
5656
array_unique(
57-
array_merge($this->functions_asis, $params['functions_asis'])
57+
array_merge($this->functions_asis, $params['functions'])
5858
);
5959
}
6060
if (isset($params['functions_safe']))

tests/libraries/TwigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function testFunctionAsIs()
8080
{
8181
$obj = new Twig([
8282
'paths' => __DIR__ . '/../templates/',
83-
'functions_asis' => ['md5'],
83+
'functions' => ['md5'],
8484
'cache' => false,
8585
]);
8686

0 commit comments

Comments
 (0)