Actions

Difference between revisions of "JModuleHelper/renderModule"

From Joomla! Documentation

(Reviewed and improved.)
 
Line 1: Line 1:
{{review}}
+
This method will return the output HTML of the module.  All language variables are translated.  The output from the module will be framed by any chrome styles specified.  If the '?tp=1' argument is added to the request URL then the 'outline' chrome style will be automatically appended to the end of the chrome style cascade.
 
===Syntax===
 
===Syntax===
''void''   renderModule ( $module, [ $attribs = array()])
+
''string'' renderModule( $module, $attribs )
  
 
where:
 
where:
Line 11: Line 11:
 
|-
 
|-
 
|$module
 
|$module
|Object
+
|object
|The module object see [[JModuleHelper/getModule]]
+
|The module object.  This can be obtained by calling [[JModuleHelper/getModule|JModuleHelper::getModule]] or [[JModuleHelper/getModules|JModuleHelper::getModules]].
 
|
 
|
 
|-
 
|-
 
|$attribs
 
|$attribs
|Array
+
|array
|$attirbs['style'] defines which chrome will frame the output of the module. See: [[What is module chrome?]]
+
|An optional array of attributes. See note below.  This array will be passed to the module chrome code.
 
|
 
|
 
|}
 
|}
=== What does this method do? ===
+
 
This method will return the output html of the module. Language variables (JText::_('Say something');) are being translated. Furthermore the output of the module will be framed by a chrome (See: [[What is module chrome?]]). The default name of the chrome is 'none'.
+
The $attribs array is passed in its entirety to the [[What is module chrome?|module chrome]] code.  Since this method will generally be called during processing of a ''<jdoc:include ... />'' tag in the template, this array is typically expected to contain:
 +
{| class="wikitable"
 +
!Element
 +
!Description
 +
|-
 +
|name
 +
|The name of the module.
 +
|-
 +
|style
 +
|Defines which chrome(s) will frame the output of the module.  This will be a space-separated string of module chrome style names. If no 'style' attribute is specified then the 'none' chrome style is used, which just outputs the raw HTML from the module.
 +
|}
 +
Other attributes may also be required by specific module chrome styles.
 +
 
 
===Example===
 
===Example===
In the following example we'd like to load the 'mainmenu' module and particularly, we want to load the module with the title 'Key Concepts'. Furthermore we want to frame the output with the xhtml chrome:
+
Render the 'mod_mainmenu' module with the title 'Key Concepts'. Frame the output with the 'xhtml' chrome:
 
<source lang="php">
 
<source lang="php">
jimport('joomla.application.module.helper');
+
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mainmenu', 'Key Concepts');
+
$module = JModuleHelper::getModule( 'mainmenu', 'Key Concepts' );
 
$attribs['style'] = 'xhtml';
 
$attribs['style'] = 'xhtml';
echo JModuleHelper::renderModule($module, $attribs);
+
echo JModuleHelper::renderModule( $module, $attribs );
/* OUTPUT HTML:
+
</source>
 +
which will output:
 +
<source lang="html4strict">
 
<div class="moduletable_menu">
 
<div class="moduletable_menu">
 
     <h3>Key Concepts</h3>
 
     <h3>Key Concepts</h3>
Line 38: Line 52:
 
     </ul>
 
     </ul>
 
</div>
 
</div>
*/
 
 
</source>
 
</source>
  
 
===See also===
 
===See also===
* [[JModuleHelper/getModule]]
+
* [http://api.joomla.org/Joomla-Framework/Application/JModuleHelper.html#renderModule JModuleHelper::renderModule on api.joomla.org]
 +
* [[JModuleHelper/getModule|JModuleHelper::getModule]]
 +
* [[What is module chrome?]]
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JModuleHelper]]</noinclude>
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JModuleHelper]]</noinclude>

Latest revision as of 15:52, 7 February 2009

This method will return the output HTML of the module. All language variables are translated. The output from the module will be framed by any chrome styles specified. If the '?tp=1' argument is added to the request URL then the 'outline' chrome style will be automatically appended to the end of the chrome style cascade.

Syntax

string renderModule( $module, $attribs )

where:

Argument Data type Description Default
$module object The module object. This can be obtained by calling JModuleHelper::getModule or JModuleHelper::getModules.
$attribs array An optional array of attributes. See note below. This array will be passed to the module chrome code.

The $attribs array is passed in its entirety to the module chrome code. Since this method will generally be called during processing of a <jdoc:include ... /> tag in the template, this array is typically expected to contain:

Element Description
name The name of the module.
style Defines which chrome(s) will frame the output of the module. This will be a space-separated string of module chrome style names. If no 'style' attribute is specified then the 'none' chrome style is used, which just outputs the raw HTML from the module.

Other attributes may also be required by specific module chrome styles.

Example

Render the 'mod_mainmenu' module with the title 'Key Concepts'. Frame the output with the 'xhtml' chrome:

jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule( 'mainmenu', 'Key Concepts' );
$attribs['style'] = 'xhtml';
echo JModuleHelper::renderModule( $module, $attribs );

which will output:

<div class="moduletable_menu">
    <h3>Key Concepts</h3>
    <ul class="menu">
         <li class="item40"><a href="/extensions"><span>Extensions</span></a></li>
         <li class="item38"><a href="/content-layouts"><span>Content Layouts</span></a></li>
         <li class="item43"><a href="/example-pages"><span>Example Pages</span></a></li>
     </ul>
</div>

See also