Custom Module additional layout

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
User avatar
Perino
Joomla! Intern
Joomla! Intern
Posts: 68
Joined: Fri Nov 01, 2013 4:52 pm

Custom Module additional layout

Post by Perino » Sun Aug 10, 2014 6:57 pm

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.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30888
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Custom Module additional layout

Post by Per Yngve Berg » Sun Aug 10, 2014 7:09 pm


RedEye
Joomla! Ace
Joomla! Ace
Posts: 1460
Joined: Sat Jan 21, 2006 8:42 pm

Re: Custom Module additional layout

Post by RedEye » Mon Aug 11, 2014 3:41 am


User avatar
Perino
Joomla! Intern
Joomla! Intern
Posts: 68
Joined: Fri Nov 01, 2013 4:52 pm

Re: Custom Module additional layout

Post by Perino » Mon Aug 11, 2014 1:19 pm

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?!

RedEye
Joomla! Ace
Joomla! Ace
Posts: 1460
Joined: Sat Jan 21, 2006 8:42 pm

Re: Custom Module additional layout

Post by RedEye » Mon Aug 11, 2014 4:19 pm

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.

blustrawberri
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Thu Apr 10, 2014 7:58 am

Re: Custom Module additional layout

Post by blustrawberri » Fri Aug 29, 2014 3:11 pm

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

blustrawberri
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Thu Apr 10, 2014 7:58 am

Alternative Layouts for selfmade module

Post by blustrawberri » Fri Aug 29, 2014 3:58 pm

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:

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


Locked

Return to “Joomla! 3.x Coding”