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()) ?>
</a>
</span>
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
Valentin
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() ?>
</a>
<?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 I’m so stupid haha
Thanks a lot !