Tuesday, April 10, 2012

[Joomla]Execute Modules with Parameters

In other post Execute Modules Manually, I showed how to load modules but without setting its parameters which is somewhat a downside because what if you want to set some parameters.

So here's how to manually load a module and also settings its parameters:
//load module
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$Module = &JModuleHelper::getModule('mod_adsmanager_ads_zb');

//set module params
$Params  = "param1=0\n\rparam2=text here";
$Module->params = $Params;

//display module
echo $renderer->render($Module);

Note that I set two parameters and they are separated using \n\r

You can also write it in a cleaner way:
$param_separator = "\n\r";
$Params  = "param1=0" . $param_separator;
$Params .= "param2=text here";

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...