API16:JModuleHelper/renderModule
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
Description
Render the module.
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 then // 1.6 3PD $lang->load($module->module, JPATH_BASE, null, false, false) || $lang->load($module->module, dirname($path), null, false, false) || $lang->load($module->module, JPATH_BASE, $lang->getDefault(), false, false) || $lang->load($module->module, dirname($path), $lang->getDefault(), false, false); $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] SeeAlso:JModuleHelper/renderModule
Examples
<CodeExamplesForm />
