1 minute reading time (248 words)

How to access Module parameters anywhere inside Joomla code?

How to access Module parameters anywhere inside Joomla code?

In Joomla, Module configurations are stored as Module parameters. Typically you only need to use parameters in the module itself. However, sometimes you might need to access them from other places like your component or a plugin. And this can get especially tricky when you have multiple copies of the module. 

A live case example for this is SocialAds Modules. In this case we need to know in places other than the module itself what parameters each copy of the SocialAds module is configured with.

This blog will show you how you can do this. 

Note: This Blog is purely targeted towards developers!

This is how it is done!

First lets get module id (optional. Only needed if you have multiple copies of same module)

In the case above, we have a SocialAds module that lets you configure the zone from which Ads should be picked up. You can create multiple copies of the module and configure each differently. However we don't run the code for all this in the module for efficiency reasons. Here is how you can get the module id for each module and pass it to your common function. You can use the subsequent code to get the module params.

// Take a module id 
$moduleId = $module->id;

//Pass  module id to a function
functionName($params, $moduleId);

Get module parameters

jimport( 'joomla.application.module.helper' );
// For example  Module_Name is login
$module = JModuleHelper::getModule(‘ Modul_Name’ );
echo '
';
print_r( $module );
echo '
';

 

 

oie 2091545kJ6pG0Wx

1
The Joomla Speak! In Conversation with Henry Nguye...
The Joomla Speak! In Conversation with Sarah Watz

Related Posts