J3 Issue ?
avatar shur
shur
23 Sep 2018

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.

Most often you come across this:

When installing a new module with several layouts in package.
When you want to create one more module instance.

Steps to reproduce the issue

  1. 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”.

  2. 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.

Expected result

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"
                />
avatar shur shur - open - 23 Sep 2018
avatar joomla-cms-bot joomla-cms-bot - change - 23 Sep 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 23 Sep 2018
avatar franz-wohlkoenig franz-wohlkoenig - change - 23 Sep 2018
Category com_modules
avatar SharkyKZ
SharkyKZ - comment - 23 Sep 2018

Add _: prefix to indicate it should use the layout from the module. E.g. default="_:horizontal".

avatar ggppdk
ggppdk - comment - 23 Sep 2018

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>
avatar shur
shur - comment - 23 Sep 2018

@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

avatar brianteeman brianteeman - change - 25 Sep 2018
Labels Added: J3 Issue
avatar brianteeman brianteeman - labeled - 25 Sep 2018
avatar franz-wohlkoenig franz-wohlkoenig - change - 28 Sep 2018
Status New Discussion
avatar brianteeman
brianteeman - comment - 21 Feb 2019

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

avatar Quy
Quy - comment - 12 May 2019

@brianteeman OK to close?

avatar HLeithner
HLeithner - comment - 13 May 2019

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.

avatar HLeithner HLeithner - close - 13 May 2019
avatar HLeithner HLeithner - change - 13 May 2019
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2019-05-13 09:13:29
Closed_By HLeithner
avatar Quy
Quy - comment - 13 May 2019

Should the doc page be updated about _:? https://docs.joomla.org/Modulelayout_form_field_type

avatar HLeithner
HLeithner - comment - 13 May 2019

If you can do this please do so.

Add a Comment

Login with GitHub to post a comment