1

In module development, I'm using a field for menu item (from these docs https://docs.joomla.org/Menuitem_form_field_type). I can work out to to show the menu item in the XML:

<field name="menuitem1" type="menuitem" default="45" label="Select a menu item" description="Select a menu item" />

I can then echo this for the frontend:

<a href="<?php echo $params->get('menuitem1');?>" >

But this only shows the ID of that menu item, how can I set it to be the actual URI for the menu item selected?

1 Answer 1

1

You can get the URL using the following:

$itemid = $params->get('menuitem1', 0);

$app = JFactory::getApplication();
$menu = $app->getMenu();
$link = $menu->getItem($itemid)->link;

echo JRoute::_($link);

$link will provide you with a non-SEF URL, then as shown above, you can use JRoute to convert it to a SEF URL.

Hope this helps

2
  • You're welcome :)... I was just going to say, there shouldn't be an error :)
    – Lodder
    Commented Jun 22, 2015 at 16:15
  • Oddly, there's an error shown when linking to the same page - but only a 'Notice' - gone after clearing the cache. Commented Jun 22, 2015 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.