API15:JModuleHelper/renderModule
From Joomla! Documentation
Description
Render the module.
Template:Description:JModuleHelper/renderModule
Syntax
static renderModule($module, $attribs=array())
| Parameter Name | Default Value | Description |
|---|---|---|
| $module | A module object. | |
| $attribs | array() | An array of attributes for the module (probably from the XML). |
Returns
strign The HTML content of the module output.
Defined in
libraries/joomla/application/module/helper.php
Importing
jimport( 'joomla.application.module.helper' );
Source Body
public static function renderModule($module, $attribs = array())
{
static $chrome;
$option = JRequest::getCmd('option');
$app = &JFactory::getApplication();
// Record the scope.
$scope = $app->scope;
// Set scope to component name
$app->scope = $module->module;
// Get module parameters
$params = new JParameter($module->params);
// Get module path
$module->module = preg_replace('/[^A-Z0-9_\.-]/i', '', $module->module);
$path = JPATH_BASE.'/modules/'.$module->module.'/'.$module->module.'.php';
// Load the module
if (!$module->user && file_exists($path))
{
$lang = &JFactory::getLanguage();
// 1.5 or Core
$lang->load($module->module);
// 1.6 3PD
$lang->load($module->module, dirname($path));
$content = '';
ob_start();
require $path;
$module->content = ob_get_contents().$content;
ob_end_clean();
}
// Load the module chrome functions
if (!$chrome) {
$chrome = array();
}
require_once JPATH_BASE.'/templates/system/html/modules.php';
$chromePath = JPATH_BASE.'/templates/'.$app->getTemplate().'/html/modules.php';
if (!isset($chrome[$chromePath]))
{
if (file_exists($chromePath)) {
require_once $chromePath;
}
$chrome[$chromePath] = true;
}
//make sure a style is set
if (!isset($attribs['style'])) {
$attribs['style'] = 'none';
}
//dynamically add outline style
if ($app->getCfg('debug_modules') && JRequest::getBool('tp')) {
$attribs['style'] .= ' outline';
}
foreach(explode(' ', $attribs['style']) as $style)
{
$chromeMethod = 'modChrome_'.$style;
// Apply chrome and render module
if (function_exists($chromeMethod))
{
$module->style = $attribs['style'];
ob_start();
$chromeMethod($module, $params, $attribs);
$module->content = ob_get_contents();
ob_end_clean();
}
}
$app->scope = $scope; //revert the scope
return $module->content;
}
[Edit See Also] Template:SeeAlso:JModuleHelper/renderModule
Examples
<CodeExamplesForm />