{% set collection = page.collection.visible(order('folder','asc')) %}
{% if collection is empty %}
{% set collection = page.parent.collection.visible(order('folder','asc')) %}
{% if collection is empty %}
{% set collection = page.parent.parent.collection.visible(order('folder','asc')) %}
{% endif %}
{% endif %}
{% for p in collection %}
`
I’d like to have “collection” sorted in alphanumeric order according to the folder names.
It allrignt locally on my PC, but not in the copy on my production server…
Sorry, I post a better formatted version :
I’d like to sort the variable named “collection” in alphanumeric order according to the folder names.
It’s alright locally on my PC, but not in the copy on my production server…
sections.html.twig :
{% set collection = page.collection.visible(order('folder','asc')) %}
{% if collection is empty %}
{% set collection = page.parent.collection.visible(order('folder','asc')) %}
{% if collection is empty %}
{% set collection = page.parent.parent.collection.visible(order('folder','asc')) %}
{% endif %}
{% endif %}
{% for p in collection %}
{% set current_parent = p.active
? 'active'
: '' %}
<li class="nav-item {{ current_parent }}">
<a href="{% if activetag %}{{ p.url ~ '/filter:' ~ activetag }}{% else %}{{ p.url }}{% endif %}">{{ p.menu }}</a>
</li>
{% if p.children.visible.count != 0 %}
{% if p.active or(p.slug == page.parent.slug) %}
<ul class="nav">
{% for child in p.children.visible %}
{% set current_child = child.active
? 'active'
: '' %}
{% if activetag %}
{% if activetag in child.taxonomy['filter'] %}
<li class="nav-item {{ current_child }}">
<a href="{% if activetag %}{{ child.url ~ '/filter:' ~ activetag }}{% else %}{{ child.url }}{% endif %}">{{ child.menu }}</a>
</li>
{% endif %}
{% else %}
<li class="nav-item {{ current_child }}">
<a href="{% if activetag %}{{ child.url ~ '/filter:' ~ activetag }}{% else %}{{ child.url }}{% endif %}">{{ child.menu }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
{% endif %}
{% endfor %}
</ul>
@Karmalakas, Well spotted, but I think that will not make much difference because Collection::visible() does not take any parameters.
The resulting collection will still be all visible pages, with the order as defined in the header of the page. The ordering parameter in Twig will just be ignored.
Hmm… I thought page.collection will return ordered as defined in frontmatter, then .visible will leave just visible items, and then .order() should do it’s thing on the collection it gets If not, then don’t know how to apply second ordering