I wrote a component with two views,

My client requested that I show a different menu on the detail pages.

I tried creating a new menu item pointing to the detail page, and a param to set the correct Itemid in the main page, and it picks it up correctly, however it adds the second menu alias to the url i.e. https://example.com/second-menu-item-alias/somealias.

I know I can:

  • modify the template, create two positions and show each according to the input params;
  • override the menu module to add the required logic there;
  • use Nonumber's or other extensions to handle it.

But before I resort to those, I would really like to know if there is a solution I can use from my component.

Thank you.


Yes you can do it without making many changes in your code add a custom position to your view using

JHTML::_('content.prepare', '{loadposition mycustom-top}')

Go to modules and on the module that you want to render here set position to mycustom-top

Note you will not get the option for this position, but write the position in the text field of position and press enter.

Hope this helps. All the best, if you face any issue or query please post a comment.

  • Thank you for your answer, but this would force me to copy all the header part of the template into my component, which is even less portable than the alternatives. – Riccardo Zorn Dec 12 '17 at 21:18
  • No that will not be the case as the template will load the view, you just need to add this position and the css accordingly. – Pratyush Dec 13 '17 at 7:19

Turns out the solution was incredibly easy: I added a param to the main view where I input the Itemid of a second menu item, hidden, where I configured my alternative modules layout.

Then in the detail page layout I simply added:

$set_itemid = $this->params->get('set_itemid',0);
if ($set_itemid) {
    $app = JFactory::getApplication();

So I'm just overwriting the Itemid parameter with the correct one I have built my layout on. The page with the other Itemid is never used directly, I'm just tricking Joomla! in thinking it should renders the modules of that page.

This works because when I'm rendering the component, the url is already decoded for my component (so it's not going to cause problems here), but the modules still need to be rendered.

I am not sure this will work with 3rd party cache managers or SEF products, but with basic Joomla 3.8 routing and cache it seems to behave just fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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