2
votes

I try to get id of module by position in templates/mytemplate/index.php (Joomla 3.3.3) and use the code:

jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('top');
echo $module->id;

but I get nothing. What's wrong?

1

1 Answers

2
votes

With JModuleHelper::getModule, you are only allowed to define the name or type of the module. You cannot define the position. So instead, type in the name, for example:

jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('login');

echo $module->id;

If you still want to get the module by position, then you must use JModuleHelper::getModules. Note the s at the end.

Update:

As the second option will give you an array of multiple modules that belong to that position, you will need to use the following which will give you the first instance of the array:

echo $modules[0]->id;

Hope this helps