I´ve the following presets in my db stored as LONGTEXT:
[
{
"timewindow": "21:00-24:00",
"mas": "2"
},
{
"timewindow": "00:00-02:00",
"mas": "2"
},
{
"timewindow": "02:00-04:00",
"mas": "2"
}
]
I pass this JSON String to my TWIG3-Template and try to iterate over it, like this:
{% set presets = service.preset|json_encode|raw %}
{% for preset in presets %}
<tr id="{{service.shortname}}_shift_{{loop.index}}">
<td><input type="text" name="{{service.shortname}}_timewindow_{{loop.index}}" value="{{preset.timewindow}}" required></td>
<td><input type="number" name="{{service.shortname}}_amountma_{{loop.index}}" value="{{preset.mas}}" required></td>
</tr>
<input type="hidden" name="{{service.shortname}}_id_{{loop.index}}" value="{{service.id}}" required>
{% endfor %}
Unfortunately there is no output. When I display the variable {{presets}} it shows an escaped view of the JSON like this:
[{\"timewindow\": \"21:00-24:00\", \"mas\": \"2\"},{\"timewindow\": \"00:00-02:00\", \"mas\": \"2\"},{\"timewindow\": \"02:00-04:00\", \"mas\": \"2\"}]
Maybe there is the problem? So my question is, how can I translate a JSON string into a usable TWIG object.