11

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

1 Answer 1

13

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.

3
  • how will the above code display a specific module?
    – saibbyweb
    Commented May 29, 2014 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
    Commented May 29, 2014 at 6:38
  • 3
    I think creating the $renderer variable is unnecessary since you're not using it anywhere in the code?
    – Ejaz
    Commented Jan 20, 2016 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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