2

I'm developing a module for displaying list of articles. In order to find the URL of an article I use ContentHelperRoute::getArticleRoute($item->slug, $item->catid). By default, it returns the article link (OK) but if it finds a menu item linking to this article It returns this menu item link.

This is my scenario:

  • I have an article "My article".
  • I have 2 menus "Main menu" (I created if first) and "Special menu".
  • On each menu, I have a menu item linking to the same article but they are displayed with a different layout.
  • In "Main menu", I have a menu item "Default article" using the default layout.
  • In "Special menu", I have a menu item "Special article" using a customized layout.

It seems that ContentHelperRoute::getArticleRoute($item->slug, $item->catid) returns the link to "Default article". How can I get the link to "Special article"? Is there a way to get the link from the menu "Special menu" instead of "Main menu"?

  • Just to check because there are layout and template styles and the language is somewhat overlapping when referencing them.... You are different "Template Style" on each menu item as defined by the "Details" tab inside the menu item settings? – David Hayes Nov 21 '17 at 5:11
  • Not sure to correctly understand. On the "Template Style", I used 2 different layouts ("My Template - Default" and "Another Template - Custom"). Finally, I found a solution. In the module parameters, I added a parameter for selecting the target Menu then in the code I parse the menu items for the choosen Menu and select the menu item matching with the correct article. – titchagcreation Nov 28 '17 at 12:29
  • @titchagcreation Did your solution work for you? If so that is great. You should post it as an answer and mark it correct solution so everyone can know this is a question with a solution. – JoelAZ Jan 29 '18 at 6:19
0

Finally, I found a solution. In the module parameters, I added a parameter for selecting the target Menu then in the code I parse the menu items for the choosen Menu and select the menu item matching with the correct article.

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.