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.

General

nextSibling in partials

Solved by Lars View solution

Started by Lars 7 years ago · 1 replies · 492 views
7 years ago

Hi, I am currently moving from kirby to grav and do struggle with nextSibling.

The page structure of my radio archive looks like this

1991
|- 01.01.91
|- 08.01.91
|- ...
|- 28.01.91
1992
|- 02.01.92
|- 09.01.92
|- ...
|- 29.12.92

What I want to do is on each of the subpage show a link and title to the next and if possible previous sibling. What I am currently able to do is get all siblings but not the previous and next one.

I know this code snippet is not correct but I just cannot wrap my head around how to get a simple page.nextSibling().title

TWIG
{% set options = { items: {'@self.siblings':''}, 'limit': 10, 'order': {'by': 'date', 'dir': 'desc'}} %}
{% set my_collection = page.collection(options) %}

<h3>Siblings</h3>

<ul>
{% for p in my_collection %}
        <li><a href="{{ p.url }}">{{ p.title }}</a></li>
{% endfor %}
</ul>
7 years ago Solution

I scoured all the posts here in the forum and found my work-around. But I do not know if it is supposed to work that way.

1991
|- 01.01.91 (week.md)
|- 08.01.91 (week.md)
|- …
|- 28.01.91 (week.md)
1992
|- 02.01.92 (week.md)
|- 09.01.92 (week.md)
|- …
|- 29.12.92 (week.md)

In my week.md I added a content section where @page has to be set according depending on the parent:

YAML
content:
    items:
      '@page': '/1991'

My partial now includes just one line I can work with.

<a href="{{ page.collection.nextSibling(page.path).url }}">{{ page.collection.nextSibling(page.path).title }}</a> | <a href="{{ page.collection.prevSibling(page.path).url }}"> {{ page.collection.prevSibling(page.path).title }}</a>

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 99 16 hours ago
General · by pamtbaau, 21 hours ago
1 63 21 hours ago
General · by Andy Miller, 1 day ago
0 48 1 day ago
General · by Marcel, 12 months ago
6 357 5 days ago
General · by Duc , 6 days ago
3 45 6 days ago