I would like to distribute my footer links into columns like this:
{% for column in cities|batch(4, null) %}
<ul>
{% for city in column %}
<li class="city-item"><a href="#">{{ city }}</a></li>
{% endfor %}
</ul>
{% endfor %}
https://twigfiddle.com/0h54xy/5
I can not, for the life of me, get this to work with _self.loop(pages) and am at a loss…
Yes, that would work if I could actually get the code above to work. I can not get the links returned from the navigation.html.twig to work with something like the example above. I’ve attached an example.
So you are wanting to have equal height columns, with a list of links in each, three columns in total? The example from the TwigFiddle, cities2.twig, seems to do this as expected, apart from the links. For the links, you just need to break the list into parts really, like this:
Yes, but I believe my explanation of my desired result is not making it across.
I need it to work with the navigation code. Thus being dynamic. When someone adds a new page it won’t break the footer layout. A static Yaml solution won’t do.
I take it you want to loop over pages (visible ones), and split the result into batches. Then iterate over each page in a batch, and output a list of links (with names). Something like this:
Batch with a set number (4) of pages per column (max 3)
{% for pages in pages.children.visible |batch(4, null) |slice(0, 3) %}
<ul>
{% for page in pages %}
<li>
<a href="{{ page.url }}">{{ page.menu }}</a>
</li>
{% endfor %}
</ul>
{% endfor %}
Batch with a set number (3) of columns
{% for pages in pages.children.visible |batch(pages.children.visible|length / 3) %}
<ul>
{% for page in pages %}
<li>
<a href="{{ page.url }}">{{ page.menu }}</a>
</li>
{% endfor %}
</ul>
{% endfor %}
The first of course limited in that if there are more than 12 pages, they will not be included. The latter seems more apt, but a larger number of pages would of course mean longer (higher) columns, unless you filter the pages.