Set twig variable to json file as an include Set twig variable to json file as an include json json

Set twig variable to json file as an include


To capture chunks of text it is better to use the {% set var %}/{% endset %} tag. This allows you to assign "larger" amount of data to a variable. It's also possible to pass content from another file to the variable this way in combination with include.

{% set json %}    {% include "content.json" %}{% endset %}{{ json }}

(sidenote: Content captured as chunk is being treated as safe)