Written by Peter Bui Follow on
Published: 16 June 2013

There are some situations where you might need to load a Joomla module outside of the Joomla framework. 

That is, you might have a custom application that is interfacing with your Joomla website and you can't call a Joomla module the normal way with a jdoc call.

Instead, this function snippet of code can be used for other external applications where jdoc can't be called to display a module.

 

The situation where I had to use this first was on a MijoShop custom template.

There were certain module positions that I wanted to load in the template are of MijoShop, not only in the description area where you can use the {loadposition} plugin to call in the module.

function renderModule ($positionName){
   $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);
      }  
   }
}

This bit of code will do the trick. It still is intended to work within the Joomla framework just not using the jdoc method to load a module where it may not be possible. This function can be adapted and transformed to work with standard PHP.

Use the function in the code by calling the function with the define variable $positionName where $positionName is something like 'Right' or 'customPositionName'.

Hope this helps other Joomla developers and implementors out there. Has been quite useful in many occasions at PB Web Development.

Peter Bui

Peter Bui

An all round web specialist with years of experience in web design, development and open source solutions at PB Web Development

Subscribe to the Podcast

Subscribe to Newsletter

Stay up to date with the latest Joomla news, design, development, marketing and management hints and tips right in your email.

Sub Category Topics Menu

Recent Comments

This site is hosted on

Digital Ocean

Simple Cloud Hosting, Built for Developers.

 

If you don't know how to build
your own server, we recommend

 siteground logo

Fast support, reliable & cost effective

Web Hosting