5

I have noticed that with Joomla 3, any module that has more than one layout (in the tmpl folder), and in the .xml has a default layout chosen

example:

<field name="layout" type="modulelayout"
label="JFIELD_ALT_LAYOUT_LABEL"
description="JFIELD_ALT_MODULE_LAYOUT_DESC"
default="mylayout" />

When adding the module in the administration, if I go to the Advanced tab to check/select the "Alternative Layout", it shows the first alphabetically and not the default specified in the xml!

Is this due to some change to the way I should be defining the default?

Or is it related to a bug?

1 Answer 1

3

Based on looking at the code of the modulelayout.php file, it looks like you may have to preface the layout name with _:. So your xml field would look like this:

<field name="layout" type="modulelayout"
label="JFIELD_ALT_LAYOUT_LABEL"
description="JFIELD_ALT_MODULE_LAYOUT_DESC"
default="_:mylayout" />

I'm seeing in the file that it sets a select option as such:

$groups['_']['items'][] = JHtml::_('select.option', '_:' . $value, $text);

This is, I'm guessing, used to distinguish it from files with the exact same name that are in the template (as overrides). Those would be prefaced with the template name, based on this code:

$groups[$template->element]['items'][] = JHtml::_('select.option', $template->element . ':' . $value, $text);

I have no idea if this is actually documented somewhere else. But for more fun, try perusing the code at libraries/legacy/form/field/modulelayout.php. It's not too crazy. :)

1
  • It's not too crazy and it works, bloody hell you solved it! :)
    – jackJoe
    Commented Apr 25, 2014 at 9:09

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.