Can i display a Joomla module using PHP? What would be the script to achieve this? (If it's possible!)


Try this,

Did you mean to render the module output using a PHP script? In which case, then take a look at this:

For older versions < Joomla3.x

$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');      
$module   = JModuleHelper::getModule('mod_fmDataGrid');

$params = "param1=bruno\n\rparam2=chris";
$module->params = $params;

echo $renderer->render($module);

For latest version. Joomla3.x

$modules  = JModuleHelper::getModules("dashboard_main");
$document = JFactory::getDocument();     
$attribs  = array();
$attribs['style'] = 'xhtml';

foreach ($modules as $mod)
    echo JModuleHelper::renderModule($mod, $attribs);

Hope this helps.

| improve this answer | |
  • how will the above code display a specific module? – saibbyweb May 29 '14 at 6:31
  • Pass the module name like "mod_fmDataGrid" or "dashboard_main", If you need to pass its param too then check params and attrb options – Jobin May 29 '14 at 6:38
  • 3
    I think creating the $renderer variable is unnecessary since you're not using it anywhere in the code? – Ejaz Jan 20 '16 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.