2

Let's say I already have a menu_item_A set as a "category blog" page of category myblog, and the template associated with it is templateA. When I go to this page and click one of the articles, if there is no menu item directly associated with this article, then the article content page will adopt its category blog page's template.

Now if I create another menu item menu_item_B, and set it as "category blog" of myblog too, but the template is now templateB. What template will the article page use?

I test this on my website, no matter what you click the article on pageA or pageB, the article content page will allways adopt templateA.

My question is: How can you let the article content page use templateB without setting a single article menu item for that particular article?

I am aware of extensions like Module Anywhere, but I kind of want to solve it with native Joomla.

  • It's not 100% clear of what you are trying to achieve. What you mean when you say templateA and templateB? Are you talking about different Joomla templates (extensions), or articles' view template files? Do you want to have different css per articles? Please update your question with more details about your specific case. – FFrewin May 13 at 18:57
3

Last time I need to get different style depending of the component without using menu, I've used a trick using the Jinput variable

$jinput = JFactory::getApplication()->input;
$jinput->get('option'); //Return the component you're viewing
$jinput->get('view'); //Return the component "view" you're viewing

In you're template files you can do an if/else statement on these variable to catch if you're on a article page or a category page and then display the correct wanted display.

if($jinput->get('option') == 'com_content' && $jinput->get('view') == 'article')  {
   //display the article template
}
else{
   //display the category template
}

Hope it helps !

  • 1
    This is the solution I'd use. Additionally, if you want this override for only specific menus (instead of all com_content articles) then you can check for the current menu item via JFactory::getApplication()->getMenu()->getActive(); – Drew G May 14 at 3:17
1

I can't think of any good reasons to create 2 menu items for the exact same database content. So I would advise you to drop the idea of having 2 menu items for the same category of articles.

Regarding why your articles of that category always end-up loading the parameters set for the first created menu item read here: Why does Category View use Home Page Itemid when displaying the articles?

*I also don't think extensions like Modules Anywhere are of any help here.

1

You're getting this behavior because articles resolve to the first menu item with their category. That said, all you need to do is reverse the menu item order.

menu_item_A should use templateB and menu_item_B should use templateA. Articles will resolve to menu_item_A (even if accessed through menu_item_B) and therefore use templateB. Meanwhile you can still view the category page with templateA by entering it through menu_item_B.

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.