Reputation: 21
I am coding an own Joomla menu-module. Now I am asking how to build the correct URL of the menu items. So far:
$app = JFactory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
$items = $menu->getItems('menutype', 'mainmenu');
foreach($items as $i => $item) {
echo '<li><a href="'.$item->link.'">'.$item->title.'</a></li>';
}
I know that I can get the ->link or the ->alias, but how do I know what the user customized in Joomla? So if he wants to use SearchEngineFriendly URL so I have to use ->alias for URL, but how do I know? What is the best way to create a proper URL-Link for the menu?
Thanks for your help
Upvotes: 2
Views: 62
Reputation: 1328
Use JRoute, like that:
echo '<li><a href="'.JRoute::_($item->link).'">'.$item->title.'</a></li>'
Upvotes: 2