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.

Themes & Styling

isFirst() not working in page collection

Started by O 5 years ago · 3 replies · 528 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 Pedro M, 2 months ago
4 197 2 months ago
Themes & Styling · by Ian, 2 months ago
3 93 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 454 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 47 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 127 3 months ago