I need to be able to specify different layouts of the same View by way of the Menu item, resulting in a url having &layout=blahblah appended. - NOT using a template override.

i.e.: index.php?option=com_things&view=things&layout=tabs

This question has the code and structure I'm using, and her own answer solves the problem of the url, but how does one get the choice of layouts to appear when the menu item is being created.

This documentation appears to be referring to it, but where does this field belong to get a list of the available layouts when creating the menu item?

Update: This is the actual file structure - where/how to get "default" or "tabs" to appear as a choice when creating a menu item. The alternative layout works if I manually type &layout=tabs into the browser, so how does one get it included in the link that Joomla generates from the menu item?

enter image description here

3 Answers 3


This may not be a 100% perfect approach to this, but it is the solution that I have used for years and it works with no issues. It will allow you to create individual menu items per layout as you requested.

In your default.xml file for your view:

<?xml version="1.0" encoding="utf-8"?>
    <layout title="My View Title">
        <message><![CDATA[This is my custom view title]]></message>
    <fields name="request">
        <fieldset name="request">
                label="Custom Layouts"
                description="Available View Layouts"
                <option value="-1">Choose a Layout</option>
                <option value="default">Layout 1</option>
                <option value="layout2">Layout 2</option>

In your view.html.php:

$app = JFactory::getApplication();
$JInput         = $app->input;
$this->layout   = $JInput->get('_layout','','string');
if($this->layout == ''){
    $this->layout = 'default';
  • According to docs.joomla.org/Retrieving_request_data_using_JInput, is the whole view snippet not the same as $this->setLayout(JFactory::getApplication()->input->get('_layout', 'default', 'string'));? Or is it vital to declare all of those variables for another reason? Commented Apr 8, 2020 at 12:48
  • 1
    Technically yes that code does work. I personally declare the individual variables for other reasons. For instance If I want to include specific CSS / JS files based on which layout has been declared I can run those through a switch statement and add it to the $doc prior to page load, etc. $app can be used for other things as well like clearing out a user state variable. Plenty of reasons to separate them out IMHO. But yes a shortcut would be to use @mickmackusa's code.
    – Terry Carter
    Commented Apr 12, 2020 at 16:49

Currently, different layouts are considered to be different menu item types. To make your alternative layout listed as menu item type, create a tabs.xml metadata file alongside tabs.php.

  • I've done exacty that. I actually have 3 different views, each with default.php and default.xml. One of them has tabs.xml and tabs.php, but it doesn't appear as a choice when creating a "Menu Item Type" while adding a menu, so I'm trying to figure out how to add it as a choice one that view has been selected.
    – GDP
    Commented Jul 16, 2019 at 14:42

Did you put the metadata in properly?

I'm a bit confused. A really good example of connecting a layout to a menu item type is the first 8 lines of com_content's category blog XML file. In a nutshell, what you're needing in that file is a layout node. A barebones one:

<layout title="titleOfMenuItemType" option="nameOfLayout">
  <message><![CDATA[Description of Menu Item Type]]></message>

Roam through the components, there are plenty of working examples there to look through.

But it sounds almost like what you're wanting to do is make the user first select a menu item type that points to a view, and after that make the user perform a second operation to select the layout, instead of doing both in one operation. If that's really what you're after, I'm curious as to what can be gained by doing that? Maybe I'm missing something.

Maybe if you'd explain what the problem is that this two-step approach is supposed to solve, we could do a better job of getting you to a solution.

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.