Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Unable to order modules - Grav 1.4

Started by Tim Bowerbank 8 years ago · 5 replies · 1087 views
8 years ago

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

8 years ago

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

8 years ago

Think you forgot
dir: asc
Try:

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

8 years ago

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

8 years ago

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

YAML
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:

TXT
/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:

TWIG
{% 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):

YAML
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).

last edited 07/27/18 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 52 9 hours ago
Support · by Anna, 3 days ago
2 59 11 hours ago
Support · by Justin Young, 12 hours ago
1 30 12 hours ago
Support · by Duc , 1 week ago
2 65 5 days ago
Support · by Colin Hume, 1 week ago
2 56 5 days ago