Reputation: 2166
In my custom module, my themes are structured like this:
/modules/mod_ab_art/tmpl/default/default.php
/modules/mod_ab_art/tmpl/arz/default.php
I have an option for the user to select a theme from the admin section like this:
<field
name="theme"
type="list"
default="default"
label="MOD_AB_ART_THEME_LABEL"
description="MOD_AB_ART_THEME_DESC">
<option value="default">MOD_AB_ART_THEME_DEFAULT</option>
<option value="arz">MOD_AB_ART_FIELD_ARZ</option>
</field>
I also have an alternative layout option as shown below but this is not displaying anything in the dropdown list. I think this is supposed to display Default
in the dropdown list. Is it because of the theme subdirectories inside the tmpl
directory? Does alternative layout work only with a single theme?
<field name="altlayout"
type="modulelayout"
label="JFIELD_ALT_LAYOUT_LABEL"
description="JFIELD_ALT_MODULE_LAYOUT_DESC" />
Upvotes: 0
Views: 328
Reputation: 1873
Although David's answer is 100% correct, I would like to clarify the distinction between template overrides and having multiple layout files packaged with your module. In the end, they both accomplish the same things. It just depends on if you want/need the alternate layouts encapsulated within the module entirely or not.
Regardless, you would need to remove the extra directory exactly like David explained above. So your tmpl directory will have both the default.php and arz.php files in it.
The second thing would be to alter the code in your modules entry point to capture the 'theme' parameter and use it when rendering the layout:
require JModuleHelper::getLayoutPath('mod_ab_art', $params->get('theme', 'default'));
You'll notice this is identical to almost all the core modules execution of the same line of code, except it pulls the 'layout' parameter, which is a listing of layout overrides in the active template for the particular module.
Upvotes: 3
Reputation: 3731
Joomla would not expect the folders under tmpl
for a module. It would expect just the full layout to be one file and each to be named a different name to signify the layout. So you would probably do best to have layout files like this:
/modules/mod_ab_art/tmpl/default.php
/modules/mod_ab_art/tmpl/arz.php
You can have as many different files in the tmpl
folder and even different ones in the theme (typically at templates/*template_name*/html/mod_ab_art/override.php
).
Upvotes: 2