How can I use page information from the navigation in the view?

Hi.
I want to use an active page’s information from view.
I use this code in the “every” view for it now.

$container = $this->navigation("default")->getContainer();
$it = new RecursiveIteratorIterator($container, RecursiveIteratorIterator::SELF_FIRST);
$page = null;
foreach($it as $pg)
{
    if($pg->isActive()) $page = $pg;
}
echo $page->label;

It works but seems verbose.
Is there any common method to use active “page” in a view?

Here is an alternative variant:

$found = $this->navigation()->findActive(
    $this->navigation('default')->getContainer()
);
if (isset($found['page'])) {
    echo $found['page']->getLabel();
}

Reference: Introduction - laminas-navigation - Laminas Docs

The layout script is not an option for your use case?

1 Like

Thank you for your advice.

I was unaware of findActive’s existance. It’s the smart way.

And I’ll try to set the code in layout.

Thank you so much, again!