Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

isFirst() not working in page collection

Started by O 5 years ago · 3 replies · 774 views
5 years ago

I am trying to use grav's isFirst() function to detect when the user is on the first page of a page collection and to display or hide a class name but this doesn't seem to be working:

TWIG
        <div class="moduleindexcompact{% if not page.isFirst %} hidden{% endif %}">

The "hidden" class is being applied when the user is not on the first page, but when the user is on the first page, the class is still being rendered. This suggests to me that I'm not using the isFirst() function correctly. Can someone help?

5 years ago

Could you try isLast() and see if it makes a difference? There's a specific kind of issue (but not really) with page ordering in reverse, because of dates and this check is reversed

5 years ago

isLast() is also a function I would like to use but this doesn't appear to be working either.

In case this makes a difference, I have set the page collection in the content file headers:


title: Key data
content:
items:
'@page.children': '/australia/general'

Folder structure is:

  • pages
    australia
    * general
    *** 01.key-data
    default.md
4 years ago

When a ResultSet object is initially created it is positioned before the first row, so .isFirst() will return false until you call .next() to position the ResultSet on the first row (if one exists).

👍 1

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by MarkP, 2 weeks ago
3 193 2 weeks ago
Themes & Styling · by TomW, 2 weeks ago
0 111 2 weeks ago
Themes & Styling · by themetman, 3 weeks ago
1 206 3 weeks ago
Themes & Styling · by AH, 1 month ago
1 324 3 weeks ago
Themes & Styling · by Bruno, 4 years ago
6 1523 3 weeks ago