'e($page->isOpen()' without loop

Hello everyone,

For a certain design, I cannot use foreach loop page-call.
Therefore, I’m using something like this :

<span class="pages">
    <a href="<?php echo page('home')->url() ?>" >
            <?php echo html(page('home')->title()) ?>

But I need to include this in my a tag :

<?php e($subpage->isOpen(), ' class="active"') ?>

How could I do it without having a loop like this :

<?php foreach($pages->visible() as $subpage): ?>

Thanks :slight_smile:

You can simply use page('home')->isOpen() instead of $subpage->isOpen().

I would suggest a check if the page with that uid exists, though. There might always be a page with the uid home, but for other pages you should do that:

<?php if($mypage = page('home')): ?>
   <a href="<?= $mypage->url() ?>" <?php e($mypage->isOpen(), 'class="active"') ?>>
     <?= $mypage->title() ?>
<?php endif ?>

If you ever want to change the uid of the homepage you can use $site->homePage() by the way.

1 Like

Of course… it seems so obvious now :sweat_smile: I’m so stupid haha

Thanks a lot !