1

When I call my custom module from the index.php of my template, the $params variable in the modules.php, with my module settings from the backend, stays empty. So I cannot access the module parameters. Here is the module activation of my index.php:

$module = JModuleHelper::getModule('mod_custom_module','CustomModule');
$attribs['layout'] = 'startpage';
echo JModuleHelper::renderModule($module, $attribs);

The module gets loaded, but I cannot access my parameters from the backend settings. Whats wrong here?

1

To get an object for the parameters of a module, you will need to use JRegistry. Have a look at the following example based on your code:

$module = JModuleHelper::getModule('mod_custom_module','CustomModule');
$attribs['layout'] = 'startpage';
echo JModuleHelper::renderModule($module, $attribs);

// Get params and output
$params = new JRegistry($module->params);  
echo $param['param_name'];

You will of course need to change param_name to the name of your parameter.

Hope this helps

  • I added also your suggestion with JRegistry, but $params (to be more concrete, the data object of $params where the params are stored) remains empty. The module will be also loaded on a different page where the module will be loaded because of the Joomla module menue settings, here are the parameters available. – Perino Oct 14 '14 at 9:33
  • @Perino - I don't know why this isn't working for you as I've tested this just 5 minutes ago with the login module and it worked perfectly. To debug the issue, add var_dump($module); and see what gets displayed. You should see a dump of data and within that, there should be some parameter information. Let me know what you see. The after that, add var_dump($params); and you should see only the parameter information. – Lodder Oct 14 '14 at 9:40
  • object(stdClass)[864] public 'id' => int 0 public 'title' => string '' (length=0) public 'module' => string 'mod_custom_module' (length=17) public 'position' => string '' (length=0) public 'content' => string '' (length=0) public 'showtitle' => int 0 public 'control' => string '' (length=0) public 'params' => string '' (length=0) – Perino Oct 14 '14 at 9:44
  • It appears your parameters have not registered properly. Open the module in the Joomla Backend, and click the save button, then try again – Lodder Oct 14 '14 at 9:49
  • Yes, I did, but still remains empty. It seems the parameters stays empty when the module is manually loaded by the view (in this case the index.php). When the module will be loaded automatically on pages, which are defined in the menu section of the module backend settings, then the $parameters gets loaded right?! – Perino Oct 14 '14 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.