Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

isFirst() not working in page collection

Started by O 5 years ago · 3 replies · 696 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 FrViPofm, 4 weeks ago
4 487 3 weeks ago
Themes & Styling · by johan thomas, 5 years ago
1 810 3 weeks ago
Themes & Styling · by stuart young, 2 months ago
3 669 2 months ago
Themes & Styling · by Sebadamus, 3 months ago
5 688 2 months ago
Themes & Styling · by martynfoster735, 3 months ago
1 651 3 months ago