Commit 1f42ed54 authored by Marc Egger's avatar Marc Egger
Browse files

add json decode filter to twig

parent 2dc9c897
Pipeline #2341 passed with stages
in 2 minutes and 48 seconds
......@@ -5450,6 +5450,19 @@ using the `qfqlink` filter::
will render a link to *http://www.example.com*.
Json Decode
^^^^^^^^^^^
A String can be JSON decoded in Twig the following way::
{% set decoded = '["this is one", "this is two"]' | json_decode%}
This can then be used as a normal object in Twig::
{{ decoded[0] }}
will render *this is one*.
Available Store Variables
^^^^^^^^^^^^^^^^^^^^^^^^^
......
......@@ -712,6 +712,13 @@ class Report {
}, ['is_safe' => ['html']]);
$twig->addFilter($filter);
// Json decode Filter
// E.g.: {% set obj = '["this is one", "this is two"]' | json_decode%}
$filter = new \Twig\TwigFilter('json_decode', function ($string) {
return json_decode($string);
}, ['is_safe' => ['html']]);
$twig->addFilter($filter);
// render Twig
$contentTwig = $twig->render($twig_template, array(
'context' => $resultAssoc, // backward compatibility for MNF
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment