Get children of an active parent

Hello, I’m doing a docs system and I’m stuck on getting the children’s pages on a navbar. I’m trying to do it all under a single template so a ‘page(‘guide’)->children()’ is not what I’m looking into and wanna know if this could be achieved or am I just complicating my life here.

Here’s my page structure:

Docs-> (as main parent)
Guide/API/Wiki → (as primary pages)
Pages->Subpages (as children of primary pages)

The navbar should contain the children of any primary page that you are on even if you are on one of those primary pages

Maybe someone gets my idea and knows a workaround without using multiple templates or specifying the page to get the children

My logical way would be something like this but it gets all my children from all primary pages where I need just the page that I’m in, like if I’m on guide it would get me guide children (what I need is to check for an active state or something)

$page('docs')->children()->listed()

If I understood the question correctly, you can get current page with $site->page():


if ($site->page()->hasListedChildren()) {
  foreach($site->page()->children()->listed() as $child) {
    // todo
  }
}

Not sure I quite understand, but with

$pages->findOpen()->children()

You get the children of the currently open page.

Thank you guys, think you pointed me in the right direction :slight_smile:

So here’s what I did:

$page('docs')->children()->findOpen()->children()

It gets my primary pages from docs and checks which one is open and gets my children of it. Don’t know if it’s logical but it does the job for me.

That doesn’t make sense, you cannot pass an argument to $page… should be page('docs'), guess that’s a typo?

Yeah, sorry that was a controller for me, going like this

$primary = page('docs')->children()->findOpen()->children();