Add json escape strategy

This commit is contained in:
peets 2018-01-14 16:52:30 -05:00
parent dfcf0349ca
commit 281b50438a

View file

@ -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")
);