How do I insert in a twig a value from one array to another in a cycle? for example
{% for day_item in template_string %}
<div id="{{lessons.{{day_item.template_string}}.id}}" class="col-lg-2 no-padding col-md-2 col-sm-12 col-xs-12"></div>
{% endfor %}
This is a demo:
php code:
// data for twig template
$data = [
'userIds' => [1, 2, 3],
'users' => [
1 => 'Tony',
2 => 'Allen',
3 => 'Peter',
],
];
twig code:
{% for userId in userIds %}
<li>{{ users[userId] }}</li>
{% endfor %}
just use [ ]
in Twig to visit array value with a twig variable.
and the rendered html is
<li>Tony</li>
<li>Allen</li>
<li>Peter</li>