How is it possible to select an additional layout in a custom module?
I created a second layout in /modules/custom_module/tmpl/default2, but I cannot select this layout. At advanced settings 'alternative layout' it is only possible to select default.
Custom Module additional layout
Moderators: ooffick, General Support Moderators
Forum rules
- Perino
- Joomla! Intern
- Posts: 68
- Joined: Fri Nov 01, 2013 4:52 pm
- Per Yngve Berg
- Joomla! Master
- Posts: 30888
- Joined: Mon Oct 27, 2008 9:27 pm
- Location: Romerike, Norway
-
- Joomla! Ace
- Posts: 1460
- Joined: Sat Jan 21, 2006 8:42 pm
Re: Custom Module additional layout
@perino ignore the link from Per and read
http://docs.joomla.org/Layout_Overrides_in_Joomla
https://www.ostraining.com/blog/joomla/ ... r-modules/
http://docs.joomla.org/Layout_Overrides_in_Joomla
https://www.ostraining.com/blog/joomla/ ... r-modules/
- Perino
- Joomla! Intern
- Posts: 68
- Joined: Fri Nov 01, 2013 4:52 pm
Re: Custom Module additional layout
Thanks a lot. I found the problem. When the layout is called with an _ it is not possible to see the layouts in modules alternative layout. This means layout-new will be found and layout_new won't be found. This is also true by Joomla's core modules. I dont know why, iam using Joomla 3.3.3?!
-
- Joomla! Ace
- Posts: 1460
- Joined: Sat Jan 21, 2006 8:42 pm
Re: Custom Module additional layout
It's for separation, let's say you have a module what displays different content when user is logged in or is a guest, you add a layout file called "mylayout" what is displayed in the dropdown list.
Then you add "mylayout_guests" and "mylayout_users" and in the "mylayout" file you have the stuff what is needed for both files and a bit of code what loads the right layout file when needed.
Check the Joomla modules to get an idea for what this is useful.
Then you add "mylayout_guests" and "mylayout_users" and in the "mylayout" file you have the stuff what is needed for both files and a bit of code what loads the right layout file when needed.
Check the Joomla modules to get an idea for what this is useful.
-
- Joomla! Apprentice
- Posts: 7
- Joined: Thu Apr 10, 2014 7:58 am
Re: Custom Module additional layout
I have a similar problem: I can see my alternative Layouts, and I can choose one, but in the front-end just the default is rendered. In the link above it seems it should be working by just selecting it
(but it also doesn't say that I have to include the fieldset on my own to even get the layout dropdown, which I had to...)
(but it also doesn't say that I have to include the fieldset on my own to even get the layout dropdown, which I had to...)
-
- Joomla! Apprentice
- Posts: 7
- Joined: Thu Apr 10, 2014 7:58 am
Alternative Layouts for selfmade module
As I thought:
If you try to make an AL for a module of your own there are 2 things to take care of:
1. add the "Advanced" parameters to your mod_xxx.xml, or you won't be able to even see the dropdown menu:
Just put it under your other fieldset (commonly "basic").
2. Go to your mod_xxx.php and change
require_once(JModuleHelper::getLayoutPath('mod_portfolio'));
to
require JModuleHelper::getLayoutPath('mod_custom', $params->get('layout', 'default'));
The tutorial on http://cocoate.com/jdev/module didn't explain this step, the author said it's enough to implement the fieldset, everything is automatic. But as you can see the second version of getLayoutPath() here is called with the selection you made in the Advanced settings in the first place, this is essential! I took it from the Joomla core modules, there was no tutorial elsewhere.
If you try to make an AL for a module of your own there are 2 things to take care of:
1. add the "Advanced" parameters to your mod_xxx.xml, or you won't be able to even see the dropdown menu:
Code: Select all
<fieldset name="advanced">
<field
name="layout"
type="modulelayout"
label="JFIELD_ALT_LAYOUT_LABEL"
description="JFIELD_ALT_MODULE_LAYOUT_DESC" />
<field
name="moduleclass_sfx"
type="text"
label="COM_MODULES_FIELD_MODULECLASS_SFX_LABEL"
description="COM_MODULES_FIELD_MODULECLASS_SFX_DESC" />
<field
name="cache"
type="list"
default="1"
label="COM_MODULES_FIELD_CACHING_LABEL"
description="COM_MODULES_FIELD_CACHING_DESC">
<option value="1">JGLOBAL_USE_GLOBAL</option>
<option value="0">COM_MODULES_FIELD_VALUE_NOCACHING</option>
</field>
<field
name="cache_time"
type="text"
default="900"
label="COM_MODULES_FIELD_CACHE_TIME_LABEL"
description="COM_MODULES_FIELD_CACHE_TIME_DESC" />
<field
name="cachemode"
type="hidden"
default="itemid">
<option
value="itemid"></option>
</field>
</fieldset>
2. Go to your mod_xxx.php and change
require_once(JModuleHelper::getLayoutPath('mod_portfolio'));
to
require JModuleHelper::getLayoutPath('mod_custom', $params->get('layout', 'default'));
The tutorial on http://cocoate.com/jdev/module didn't explain this step, the author said it's enough to implement the fieldset, everything is automatic. But as you can see the second version of getLayoutPath() here is called with the selection you made in the Advanced settings in the first place, this is essential! I took it from the Joomla core modules, there was no tutorial elsewhere.