mirror of
https://github.com/okdana/twigc.git
synced 2024-05-08 08:26:34 +02:00
Add json escape strategy
This commit is contained in:
parent
dfcf0349ca
commit
281b50438a
|
@ -260,6 +260,9 @@ class DefaultCommand extends Command {
|
|||
case 'js':
|
||||
$escape = 'js';
|
||||
break;
|
||||
case 'json':
|
||||
$escape = 'json';
|
||||
break;
|
||||
default:
|
||||
$escape = false;
|
||||
break;
|
||||
|
@ -409,6 +412,16 @@ class DefaultCommand extends Command {
|
|||
'autoescape' => $escape,
|
||||
]);
|
||||
|
||||
$twig->getExtension('core')->setEscaper(
|
||||
'json',
|
||||
function($twigEnv, $string, $charset) {
|
||||
return json_encode(
|
||||
$string,
|
||||
\JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
$output->writeln(
|
||||
rtrim($twig->render(basename($template), $inputData), "\r\n")
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue