Each Joomla module can have several module layouts, although in the package most often there is only one - default.php (that's why this problem is difficult to detect). There is no way to specify which layout should be used by default when module have several layouts in the package. In this case the layout going first to the alphabet will always be selected as default.
When installing a new module with several layouts in package.
When you want to create one more module instance.
Create several module layout for one of standard content module, go to:
\modules\mod_articles_popular\tmpl\
and copy “default.php” file several times with new names “additional.php” and “horizontal.php”.
In Joomla administrator panel go to Extensions > Modules > New > Articles - Most Read
and see which layout will be selected in Advanced Tab > Layout:
Here, an "additional" layout will be chosen instead of the "default" layout, as it was intended.
It seems to me that it should be possible to specify a default value for the modulelayout field in manifest file. Something like:
<field
name="layout"
type="modulelayout"
label="JFIELD_ALT_LAYOUT_LABEL"
description="JFIELD_ALT_MODULE_LAYOUT_DESC"
default="modulelayoutname"
/>
Labels |
Added:
?
|
Category | ⇒ | com_modules |
Indeed, the dropdown select has values like value="_:..."
<div class="controls">
<select id="jform_params_layout" name="jform[params][layout]" style="display: none;">
<optgroup id="jform_params_layout__" label="---From Module---">
<option value="_:additional">additional</option>
<option value="_:default">default</option>
<option value="_:legacy">legacy</option>
</optgroup>
</select>
...
</div>
@SharkyKZ
Yes indeed, although it looks like an undocumented trick, but it works.
So if you need the module to use some layout (e.g. default.php) as default layout you need this lines in module manifest xml file:
<field
name="layout"
type="modulelayout"
label="JFIELD_ALT_LAYOUT_LABEL"
description="JFIELD_ALT_MODULE_LAYOUT_DESC"
default="_:default"
/>
default="_:default" - definitely not the best option and certainly not the most obvious.
Maybe someone can offer a more elegant solution for this.
In the meantime, we need to make changes to the documentation:
https://docs.joomla.org/Modulelayout_form_field_type
Labels |
Added:
J3 Issue
|
Status | New | ⇒ | Discussion |
So if you need the module to use some layout (e.g. default.php) as default layout you need this lines in module manifest xml file:
No - if you want a default layout then you just call that layout default.php
You can see that this is already done in mod_articles_news
That module has three layouts and even though nothing is defined in the xml the default.php is always selected
@brianteeman OK to close?
This is solved with the default parameter using the value "_:" the reason for using _: is that we have to select a template. In case of _: its the current.
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2019-05-13 09:13:29 |
Closed_By | ⇒ | HLeithner |
Should the doc page be updated about _:
? https://docs.joomla.org/Modulelayout_form_field_type
If you can do this please do so.
Add
_:
prefix to indicate it should use the layout from the module. E.g.default="_:horizontal"
.