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 →

Get number of child pages for menu styling

first-time theme

Solved by pamtbaau View solution

Started by Marco 6 years ago · 2 replies · 1026 views
6 years ago

Hello, first post here!
I've been experimenting Grav for some weeks and I love it! Modular pages are a stunning feature so is its speed.
That said, I ended up trying to create a theme fitting my needs.
I'm not completely new to web programming however my (limited) experience has been paused for the last ten years and a lot has happened. I primarly worked with PHP + CSS 2 and a little bit of jQuery.
I decided to start with the minimal Pure CSS framework, here's the first issue: how do I output in HTML the number of pages of the menu? This is needed in order to use Pure's Grid System i nnavigation menu.
I tried children.count() but it doesn't seem to fit this case. Or maybe I'm using it the wrong way.
Thank you!
Marco

6 years ago Solution

@phmg701, Welcome to the forum!

I wonder what you need the count for as the 'Pure' theme uses a <ul> for its menu-items.

Anyway, to get the count of visible root pages, try: pages.children.visible.count
And to get the count of visible children of the current page: page.children.visible.count

Have a look at the docs on Theme Variables where the Page and Pages object are mentioned.

last edited 07/10/20 by pamtbaau
6 years ago

Thank you, this just works!
My aim is to build a photo gallery based off PureCSS grids and those variables will be useful.
But I'm still far from this point, I'm struggling with navigation menu 😅
I'm also trying to understand how the Docs work as I'm not that used to such schemes (coming from WordPress Codex).
Thank you!

Suggested topics

Topic Participants Replies Views Activity
Support · by TomW, 2 weeks ago
8 227 9 hours ago
Support · by alex, 2 months ago
8 667 23 hours ago
Support · by Supple, 5 days ago
1 98 1 day ago
Support · by TomW, 1 week ago
3 159 3 days ago
Support · by TomW, 6 days ago
2 106 5 days ago