I came across an strange behavior and I am trying to find out if I can solve this by setting the layout to be used via the link to the category.

Here is what happened.

  • I have a template override for the category blog layout
  • I assigned it through the menu and that works fine
  • The menu type category blog layout using the custom layout override also displays child categories links
  • When I click one of the child categories it doesn't use the custom template override as the parent category, it simply defaults back to the default blog layout

So I have being trying something like the below in the custom_children.php (blog_children.php)

<a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($child->id).'&layout=customlayout');?>">

But that doesn't seem to work.

The child category does not have a menu item linked to it and given the number of categories we will have thet won't have a menu item for each.

So the questions are:

  1. Is it expected that the child category defaults back to the default blog.php?

  2. Is it possible to set the layout override via link?

I am testing this on a MAMP with PHP 7.0 and the latest joomla 3.7.5

up vote 0 down vote accepted

Likely the given information is not 100% accurate, so I 'll try to clear out a few things and reach to a conclusion.

Overrides can be made in many ways, there can be many combinations of configuration settings to deal with them.

Overrides Approaches

  1. Layout Override (global): for all items for a view - which is to just copy the view tmpl files to the respective folder in template's html folder. Then those files should be loaded instead of the default ones for any categories, disregarding.

  2. Alternative Layouts: Similar to the above, but this time we rename the tmpl files and we have to specify on the item level what layout to use.

  3. Alternative Layouts/Menu items - Copy and rename/edit also the tmpl xml file, so this layout can be selected/assigned with this new custom menu item.

From your description, I may assume that you have followed the 3rd option... but please clarify.

In this case, the layout will be used only for the category that you have selected with your custom menu item.

Trying to "trick" the sub-categories links with the &layout=customlayout is a fair attempt and would make sense. Actually &layout=template:customlayout would be closer - but this also won't work.

At some point in the past (a year or so ago), I went deeper with this and had concluded on how it works and why it couldn't work like this, but I don't remember clearly now the reasons why. My overall conclusion was that I had to create my custom MVC for it with various customizations here and there. However, since this was long time ago, maybe some things have changed now.

But in any case with these in mind, it's still possible to achieve what you want and it can be fairly simple. It somewhat depends on your overall setup, but here what you can do:

Your Override Options

  • Still assuming you have followed the 3rd option from above, just clone the customlayout.php inside your overrides folder and rename it to something like customlayoutsubs.php. If needed, create similar overrides for the other tmpl files of that layout. Then in your backend, go to the categories that you want to use this layout, edit them and in their layout option (under the Options tab) select this customlayoutsubs.php. Now the sub categories will use this new layout, that is the same as your customlayout.php alternative menu item.

  • In case this is only section of a category blog you have in your site, then you don't need an alternative menu-item. Just create your override (first option) and let all categories use that.

  • In case you just need only some categories to use that layout - create only an alternative layout (not with menu item) and assign that layout to those categories.


Some final thoughts.

I feel the overrides abilities in Joomla do actually need some polishing and improvement. For example, assign to a parent category a layout override and being able to inherit this to its subs through settings, or deeper support on the topic for alternative menu items as described above, would be nice.

It would also make sense if there was an option on the menu item level to configure such settings.

Even so though and with the confusion all these may produce, there are still plenty of options to achieve great things.

  • Thank you so much for the detailed explanation. 1 -Correct assumption it was about scenario 3. 2 -It helped me realize that alternative layouts will not show in the backend if it is a menu item alternative layout, which is a bit silly. I agree 100% having the ability to select the templates when setting up the menu for the parent and child categories would be awesome. Specially that more often than not people use categories to build something else other than simply categorizing articles. I will mark this as correct as 1 - was expected behavior 2 - layout cant be set via link either. – edger Aug 31 '17 at 2:47

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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