Thursday, 11 March 2010 23:22
There are some instances where it's desirable to load Joomla! modules outside the context of the site template - in a template override, inside a component, etc. Unfortunately, it's impossible to use the jdoc:include tags outside the template itself. In order to load a module position using PHP, use the following snippet:
<?php require_once(JPATH_ROOT.DS.'libraries'.DS.'joomla'.DS.'application'.DS.'module'.DS.'helper.php'); $document =& JFactory::getDocument(); $renderer = $document->loadRenderer('module'); $db =& JFactory::getDBO(); $db->setQuery("SELECT * FROM #__modules WHERE position='positionname' AND published=1 ORDER BY ordering"); $modules = $db->loadObjectList(); if( count( $modules ) > 0 ) { foreach( $modules as $module ) { //just to get rid of that stupid php warning $module->user = ''; $params = array('style'=>'xhtml'); echo $renderer->render($module, $params); } }
Then any modules assigned to "positionname" will be loaded wherever this code is placed!
Comments (2)
Add your comment
Latest Articles
Most Popular
The Joomla!® name is used under a limited license from Open Source Matters in the United States and other countries. Jeff Channell is not affiliated with or endorsed by Open Source Matters or the Joomla!® Project.




was wondering if you perhaps knew how to include another module (Calendar based on the DS_Calendar module), within a module based on the mod_custom module inherent in joomla. unfortunately pasting this code above in it, does not get rendered and processed at all.
thanks,
Pierre