Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
typo3
qfq
Commits
1f42ed54
Commit
1f42ed54
authored
Sep 09, 2019
by
Marc Egger
Browse files
add json decode filter to twig
parent
2dc9c897
Pipeline
#2341
passed with stages
in 2 minutes and 48 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Documentation/Manual.rst
View file @
1f42ed54
...
...
@@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
extension/Classes/Core/Report/Report.php
View file @
1f42ed54
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment