Search
Other ReReplacer questions
Forum

Get active Menu in Rereplacer with PHP

Yannick Lämmel's Avatar Yannick Lämmel
Hi there,

in Joomla 3, we use the following code to get the current page titel

search {pagetitel}
replace with

<?php
$menu = Factory::getApplication()->getMenu();
$active = $menu->getActive();
if($active->params->get('page_heading')){
$menuname = $active->params->get('page_heading');
} else {
$menuname = $active->title;
}
echo $menuname;
?>

In Joomla 4, this is not working any longer, I get the error that rhe class "Factory" is not found. We I try to register Factory before, I also get an error message.
Did something change so that the ReReplacer is not able to this information anymore?

Any help would be appreciated, thanks in advance.

kind regards,
Tanja
Peter van Westen's Avatar Peter van Westen ADMIN
Joomla has changed. Joomla 4 uses namespaces.
You would need to do something like:
$menu = \Joomla\CMS\Factory::getApplication()->getMenu();
However, ReReplacer does provide some ready-to-use Joomla objects. So you can do:
$menu = $app->getMenu();
Please post a rating at the Joomla! Extensions Directory
Yannick Lämmel's Avatar Yannick Lämmel
Hi Peter,

thank you so much for your quick help.
Works like a charme.

Kind regards
Tanja
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription