How To Render Joomla Module In Custom Components

How To Render Joomla Module In Custom Components

Joomla comes with a method to load a module into an article: the LoadModule content plug-in. This plug-in can be used with Joomla core articles. But sometimes we have the situation where we need to load any module into our code. Either in other modules or any component. We cannot load a module through module position in our component or module while coding. For Example, if you want to add mod_login to your code.

Here is the best solution by Joomla Expert Team: (JDocument/loadRenderer) class of Joomla.

The JDocument/loadRenderer class is very simple to integrate. First we need to include/import the class:
jimport( ‘joomla.application.module.helper’ );

Now make an instance of the document renderer (JDocument/loadRenderer) class:
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer(‘module’);

If there are any parameters you want to pass the set those in an array:
$params = array (‘style’=>$style);

Now render the module into a variable, by calling ‘render’ method of JDocument/loadRenderer class and pass the parameters as arguments
$moduleHtml= $renderer->render (JModuleHelper::getModule(‘mod_login’), $params);

And voila!! You can echo the fetched html any where you want
Echo $moduleHtml;


Contact us to hire expert Joomla Developers and other web solutions.

Latest Blogs