Answer the question
In order to leave comments, you need to log in
How to display a submenu from the base using twig, with a division into 3 blocks?
Good afternoon everyone! The task is to display the submenu from the database using twig, dividing it into 3 divs. That is, the submenu should have the following structure:
<div class="submenu">
<div>
<a href="menu.php?id=1">Подкатегория 1</a>
<a href="menu.php?id=2">Подкатегория 2</a>
<a href="menu.php?id=3">Подкатегория 3</a>
</div>
<div>
<a href="menu.php?id=4">Подкатегория 4</a>
<a href="menu.php?id=5">Подкатегория 5</a>
<a href="menu.php?id=6">Подкатегория 6</a>
</div>
<div>
<a href="menu.php?id=7">Подкатегория 7</a>
<a href="menu.php?id=8">Подкатегория 8</a>
<a href="menu.php?id=9">Подкатегория 9</a>
</div>
</div>
{% set counter = 0 %}
{% for menu_item in menu %}
{% if counter == 0 %}
<div>
{% endif %}
<a href="/menu.php?id={{ menu_item.id }}">{{ menu_item.name }}</a>
{% set counter = counter + 1 %}
{% if counter == 3 %}
{% set counter = 0 %}
</div>
{% endif %}
{% endfor %}
{% if counter != 0 %}
</div>
{% endif %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question