Actions

Difference between revisions of "JModuleHelper/renderModule"

From Joomla! Documentation

(New page: ===Syntax=== ''void'' renderModule ( $module, [ $attribs = array()]) where: {| class="wikitable" !Argument !Data type !Description !Default |- |$module |Object |The module object see [...)
 
(Reviewed and improved.)
 
(4 intermediate revisions by one user not shown)
Line 1: Line 1:
 +
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 10: 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.
 
|
 
|
 
|}
 
|}
 +
 +
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===
To get an installed Module, you can use the following example. This way the method checks if the module has been published, if the module is supposed to be displayed in this page, and if the user meets the access level expectations:
+
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('login');
+
$module = JModuleHelper::getModule( 'mainmenu', 'Key Concepts' );
echo '<pre>';
+
$attribs['style'] = 'xhtml';
print_r($module);
+
echo JModuleHelper::renderModule( $module, $attribs );
echo '</pre>';
+
/* RESULT:
+
stdClass Object
+
(
+
    [id] => 18
+
    [title] => Login Form
+
    [module] => mod_login
+
    [position] => left
+
    [content] =>
+
    [showtitle] => 1
+
    [control] =>
+
    [params] => cache=0
+
                moduleclass_sfx=_login
+
                pretext=
+
                posttext=
+
                login=
+
                logout=
+
                greeting=1
+
                name=1
+
                usesecure=0
+
    [user] => 0
+
    [name] => login
+
    [style] =>
+
)
+
*/
+
 
</source>
 
</source>
You can also call for a custom module, that has not been installed via the Joomla Backend. $name has start with "mod_" in this case. The method then returns a standard object. It doesn't check if the module is published or not, it doesn't check if the user has the neccessary rights to see the module.
+
which will output:
 
+
<source lang="html4strict">
<source lang="php">
+
<div class="moduletable_menu">
jimport('joomla.application.module.helper');
+
    <h3>Key Concepts</h3>
$module = JModuleHelper::getModule('mod_examplemodule');
+
     <ul class="menu">
echo '<pre>';
+
        <li class="item40"><a href="/extensions"><span>Extensions</span></a></li>
print_r($module);
+
        <li class="item38"><a href="/content-layouts"><span>Content Layouts</span></a></li>
echo '</pre>';
+
        <li class="item43"><a href="/example-pages"><span>Example Pages</span></a></li>
/*RESULT:
+
    </ul>
stdClass Object
+
</div>
(
+
     [id] => 0
+
    [title] =>  
+
    [module] => mod_examplemodule
+
    [position] =>  
+
    [content] =>  
+
    [showtitle] => 0
+
    [control] =>  
+
    [params] =>  
+
    [user] => 0
+
)
+
*/
+
 
</source>
 
</source>
 +
 
===See also===
 
===See also===
* [[JModuleHelper/renderModule]]
+
* [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