Use the JSON pretty print with the Twig json_encode filter
Published on 2019-08-17 • Modified on 2019-08-17
This is another example where the constant
Twig function can be helpful. In this case we get the JSON_PRETTY_PRINT
PHP constant to pass it to the json_encode
filter. (as the second argument of course, the first is obviously the variable to display)
{hello: "world", foo: {bar: "doo", bar2: "doo2"}}|json_encode(constant('JSON_PRETTY_PRINT')) }}
Code execution output:
{
"hello": "world",
"foo": {
"bar": "doo",
"bar2": "doo2"
}
}
More on Stackoverflow Read the doc Random snippet
Call to action
Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky 🦋
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges 🏅.
Thank you for reading! And see you soon on Strangebuzz! 😉