Exlcude OpenPage from Menu

Hi —

I’m creating a simple menu that opens when you hover it and shows the children of the page.

I’m looking for a solution to excludes the current active page from this list. Looking at the cheatsheet the “$pages->not()” and “$pages->findOpen()” seems to be the thing to do but not sure… Is this the best approach?

here is a example of the code:

<?php foreach(page('index')->children()->not('findOpen()') as $child): ?>

<li><a href="<?php echo $child->url(); ?>"><?php echo $child->title(); ?></a></li>

<?php endforeach ?>

Not tested but i think something like this should work

<?php foreach(page('index')->children()->not(page('index')->children()->findOpen()) as $child): ?>
...

Or you could just include an If statement into your loop:

<?php foreach ... ?>
<?php if ($child->isOpen()) continue; ?>
...

I’d opt for the if statement but change it to:

<?php foreach ... ?>
<?php if (!$child->isOpen()) : ?>
<li> .... </li>
<?php endif ?>
<?php endforeach ?>

Working like a charm, thank you @thomas @texnixe for the quick response