Unable to order modules - Grav 1.4

Hi,

Thank you for creating Grav - it’s brilliant.

I’m having trouble implementing custom ordering of modules.

It’s defaulting to ascending even though I have custom ordering defined. Here is the frontmatter for the primary file in the parent folder - modular.md

title: “Veterinary home page”
menu: Home
onpage_menu: true

content:
items: ‘@self.modular
order:
by: default
custom:
- _carousel
- _textBlock1
- _textAndImage
- _featureBlocks

Here’s the Twig template for modular.html.twig

{% extends ‘partials/base.html.twig’ %}
{% block content %}

{% for module in page.collection() %}
{{ module.content }}
{% endfor %}

{% endblock %}

Any help greatly appreciated. Any tips for debugging would be good.

Many thanks, Tim

Are you sure the names under custom match the names of the folders of each module?

Think you forgot
dir: asc
Try:

title: “Veterinary home page”
menu: Home
onpage_menu: true
content:
    items: ‘@self.modular’
    order:
        by: default
        dir: asc
        custom:
             - _carousel
             - _textBlock1
             - _textAndImage
             - _featureBlocks
---

Thank you for looking at that. I’m after a custom order so should I add dir: asc?

Yes, try it.
https://learn.getgrav.org/content/modular#setting-up-the-primary-page

@tim I have just installed skeleton ‘One-Page site’ (based on Quark) to test custom ordering.

TL;DR: Custom ordering works fine in demo setup mimicking your config.

‘One-Page site’ has the following modular page:

title: One Page Demo Site
menu: Home
onpage_menu: true
body_classes: title-h1h2 header-dark header-transparent

content:
    items: @self.modular

And folder structure:

/01.home
   /01._hero          # menu: Top
   /02._highlights    # menu: Highlights
   /03._callout       # menu: Easy Content
   /04._features      # menu: Features
   modular.md

And I replaced template 'modular.html.twig with:

{% extends 'partials/base.html.twig' %}

{% block content %}
   {% for module in page.collection() %}
      {{module.menu}}
      {# {{ module.content }} #}
   {% endfor %}
{% endblock %}

Running the above config shows the default ordering by number: Top / Highlights / Easy Content / Features

When I add custom ordering (reversing default order):

content:
    items: @self.modular
    order:
        by: default
        custom:
            - _features   # Features
            - _callout    # Easy Content
            - _highlights # Highlights
            - _hero       # Top

Now the list is reversed as expected: Features / Easy Content / Highlights / Top

Two notes from the docs on Ordering Options:

  • Please note that if a page is not specified in the custom ordering list, then Grav falls back on the content.order.by for the unspecified pages.
  • If a page has a custom slug, you must use that slug in the content.order.custom list.

Questions:

  • How does your folder structure look like?
  • How does the frontmatter of a child-page look like?
  • What theme are you using?
  • Have you tried a default theme like Quark?
  • If Quark shows no change, have your tried a fresh install of Grav?

NB. For legibility of code snippets you might want to use correct indentation and embed code inside ``` (triple back-ticks, or accent grave).