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
9e812cc6
Commit
9e812cc6
authored
Sep 09, 2019
by
Carsten Rose
Browse files
Merge branch 'marcTwigJsonDecodeFilter' into 'master'
add json decode filter to twig See merge request
!180
parents
2dc9c897
1f42ed54
Pipeline
#2342
passed with stages
in 2 minutes and 39 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Documentation/Manual.rst
View file @
9e812cc6
...
...
@@ -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 @
9e812cc6
...
...
@@ -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