Today I needed to render a Custom HTML module within a Joomla Component I’m currently writing.
After some research and testing this seems to be working great for me:
$mod = &JModuleHelper::getModule('custom', 'Custom HTML'); echo JModuleHelper::renderModule($mod);
I have this piece of code in my default.php file within my views/default/tmpl/ folder. The ‘custom’ refers to the module mod_custom and ‘Custom HTML’ specifies which of the mod_custom modules to call.
Lets say you have a Custom HTML module with the title MODULEA and one with the title MODULEB then you can call and render them this way:
$mod = &JModuleHelper::getModule('custom', 'MODULEA'); echo JModuleHelper::renderModule($mod); $mod = &JModuleHelper::getModule('custom', 'MODULEB'); echo JModuleHelper::renderModule($mod);
A couple of important notes:
- At the time of writing I’m using Joomla 1.7
- The modules HAS to be published.
- It needs to be assigned to the pages/menus you want it to display.