Difference sorting collection on local and production site

Hello,
For me it’s surprising, but the render isn’t the same in my production site and in my local copy. Could somebody give me an explanation ?

sections.md :

`—
title: ‘Documents’
published: true
hide_page_title: true
content:
items: ‘@self.children
order:
by: folder
dir: asc
limit: 0
taxonomy:
filter: [view1,view2]
child_type: section

section.md : bla bla bla`

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 %}

`

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>

sections.md :

---
title: 'Documents'
published: true
hide_page_title: true
content:
    items: '@self.children'
    order:
        by: folder
        dir: asc
    limit: 0
    taxonomy:
        filter: [view1,view2]
child_type: section
---

### Documents

Vous trouvez ici des fichiers...```

I believe this should be

page.collection.visible.order('folder','asc')

Same in other two places

@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.

@pzul I can imagine that the differences in folder/file ordering used by operating systems can play a role here.

For example, take the differences between Windows and Ubuntu:

  • Windows: a AA b
  • Ubuntu: AA a b

Or maybe the locale of the OS might make a difference.

What happens when you order by title, or date? Does that make a difference between dev and prod servers?

Could you perform a little test using a simple Twig and changing the ordering of the collection in the page’s frontmatter:

{% for child in page.collection %}
   {{ child.folder }}
{% endfor %}

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 :thinking: If not, then don’t know how to apply second ordering

@Karmalakas, Sure, the statements you show are different.

  • page.collection.visible.order('folder','asc'):

    • page.collection: Create and order collection based on frontmatter.
    • page.collection.visible filter only visible pages.
    • page.collection.visible.order('folder','asc'), create new ordering of visible pages.
  • page.collection.visible(order('folder','asc'))

    • page.collection: Create and order collection based on frontmatter.
    • page.collection.visible(order('folder','asc')): parameter of visible is ignored.

If I understand OP correctly, the same (incorrect) code is used on both development and production server. How

Hence, the ignored parameter should not make a difference.

Ah, yes. You might be right on that