Actions

JModuleHelper/getModules

From Joomla! Documentation

Other languages:
English • ‎français

Returns information about all modules in a given module position.

Syntax

array getModules( $position )

where:

Argument Data type Description Default
$position string The name of a module position.

Example 1

To get information on all modules in the 'top' module position:

jimport( 'joomla.application.module.helper' );
$modules = JModuleHelper::getModules( 'top' );
echo '<pre>';
print_r( $modules );
echo '</pre>';

which will output:

Array
(
    [0] => stdClass Object
        (
            [id] => 25
            [title] => Newsflash
            [module] => mod_newsflash
            [position] => top
            [content] => 
            [showtitle] => 1
            [control] => 
            [params] => catid=3
style=random
items=
moduleclass_sfx=
            [user] => 0
            [name] => newsflash
            [style] => 
        )

)

Example 2

If there are no modules enabled in the given module position then an empty array would normally be returned. However, if the '?tp=1' argument is added to the request URL then a dummy module is returned.

jimport( 'joomla.application.module.helper' );
$modules = JModuleHelper::getModules( 'myposition' );
echo '<pre>';
print_r( $modules );
echo '</pre>';

which will output:

Array
(
    [0] => stdClass Object
        (
            [id] => 0
            [title] => myposition
            [module] => mod_myposition
            [position] => myposition
            [content] => myposition
            [showtitle] => 0
            [control] => 
            [params] => 
            [user] => 0
        )

)

Example 3

To display all modules from a position you can loop through the output of getModules. In the example below we will display all modules in the 'footer_3' position.

$modules = JModuleHelper::getModules( 'footer_3' );
$attribs['style'] = 'xhtml';
foreach ($modules AS $module ) {
    echo JModuleHelper::renderModule( $module, $attribs );
}

In many instances this can also be achieved via the <jdoc:include for example <jdoc:include type="modules" name="footer_3" />.

See also