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.

Content & Markdown

Content order custom

Solved by Ron Wardenier View solution

Started by Jan Paulsen 8 years ago · 3 replies · 2395 views
8 years ago

Hello,

I am just working on a new Site on which a collection should loop over several child pages.

My first approach to give those childs a custom order was to add the numeric prefix to the folder name - and it worked as expected.
But i noticed, that the ordered childs now appeared as a submenu (child-theme extending Quark) and decided to order the items as suggested at https://learn.getgrav.org/content/collections

my frontmatter now looks like:

YAML
 ---
title: Team
content:
    items: '@self.children'
    order:
        by: default
        dir: asc
        custom:
            - dafne-maria-fiedler
            - deborah-klein
            - sylke-hannasky
            - theresa-hoerl
            - maik-toedter
            - christoph-bernhard
            - kathrin-schlosser
            - nora-jensen
            - frank-asmis
---

but for some reason the ordering is just alphabetical (the pages do not have custom slugs - it is just the foldernam)
even the

YAML
admin:
    children_display_order: collection

worked in the admin panel.

any hints on what i missed ?

Thank you in advance

8 years ago Solution

While doing some tests I discovered that if you specify ordering in the first line of the loop() macro in navigation.html.twig:

TWIG
{% for p in page.children.visible.order('custom', '') %}

and set content.order.by: custom and nothing else regarding the ordering in your parent page frontmatter or header like:

YAML
---
title: Team
content:
    items: '@self.children'
    order:
        by: custom
        custom:
            - dafne-maria-fiedler
            - deborah-klein
            - sylke-hannasky
            - theresa-hoerl
            - maik-toedter
            - christoph-bernhard
            - kathrin-schlosser
            - nora-jensen
            - frank-asmis
---

then the submenu will show your subpages in the order specified.

Unfortunately this is not the solution (keep on reading though!) because now a custom order is used for all pages even if there is no custom order specified. So Grav does not fall back to the default behaviour set in System configuration.

FWIW During my experiments I got completely lost in the documentation. Even though the order is set when I add the following code to the base.html.twig template file:

TWIG
<div>
{{ dump(page.orderBy) }}
{% for p in page.collection %}
    {{ p.title }}
{% endfor %}
</div>

the Grav Debug bar reports that orderBy is default however the list of page titles is in the required order.

At some point (and now things get exciting) I decided to experiment with the value of the order_manual frontmatter variable.

For my three pages test case I set this frontmatter:

YAML
---
title: Team
content:
    items: '@self.children'
order_manual:
    - bravo
    - charlie
    - alpha
---

And that is all there is to it!

There is no need for a modified navigation.html.twig template and there is no need to use content.order.by in the frontmatter.

Don't ask me why. I can't see or understand the logic. Looking at the Page.php code didn't help much with that.

8 years ago

I should have mentioned that the subpage folders are named:

TXT
01.alpha
02.bravo
03.charlie

It does not matter but for completeness: Only the default.md file of the page "alpha" has a title set in it's frontmatter. The other two pages do not have any frontmatter.

8 years ago

Thank you for investigating the problem!

~~for some reason using order_manual did not change anything.
Only if i name the folder with a numerical prefix the pages appear as set - but this is still the order they appear at the fs.
this would be ok for me if the pages would not appear as submenu items at the menu. Is there a way to set this per page? so i could tell the collection not to insert the childs as submenu entries~~

you were right - i had a typo in the frontmatter.
using order_manual worked perfect

Thank you very much!

Regards
Odde

last edited 04/29/18 by Jan Paulsen

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 94 8 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 184 1 year ago
Content & Markdown · by Jan L'Am, 1 year ago
4 146 1 year ago
Content & Markdown · by Leonardo, 1 year ago
3 60 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 254 1 year ago