0

I am loading a module from an article overide. The module needs different parameters depending on places I load it from. In Joomla 3, I could do use (in an article overide) :

// Load module
jimport('joomla.application.module.helper');
$module = JModuleHelper::getModule('mod_custom','Module name');
$attribs['displayFull'] = true;
$module= JModuleHelper::renderModule($module, $attribs);

Then access the displayFull custom parameter with $attribs['displayFull'] in the module overide.

In Joomla 4.x.x, I use :

use Joomla\CMS\Helper\ModuleHelper;

// Load module
$module = ModuleHelper::getModule('mod_custom','Module name');
$module = ModuleHelper::renderModule($module);

I can't figure out how to pass custom parameters to the module overide as adding an array as I did in J3.
I tried adding a custom parameter like this :

use Joomla\CMS\Helper\ModuleHelper;

// Load module
$attribs['displayFull'] = true;
$module = ModuleHelper::getModule('mod_custom','Module name');
$module = ModuleHelper::renderModule($module, $attribs);

But when I try to access $attribs['displayFull'] in the module overide, I get this error :

Warning: Undefined variable $attribs in...
2
  • In the sample of the code for Joomla 4 you aren't setting the $attribs array or passing it to the renderModule() method. Is this the code that 'doesn't work'? Or have you been using a version that includes these statements and it is that version of the code that 'doesn't work'? And what is 'doesn't work' meaning? Are you receiving an error message or is the attribute not having the effect that it has in Joomla 3?
    – Irata
    Aug 1, 2023 at 1:10
  • @Irata I updated my question with more info on the error I get in J4 using the same method as in J3
    – web-tiki
    Aug 1, 2023 at 11:10

1 Answer 1

2

Attributes aren't meant to be used inside module context and they're no longer passed there. They're now only available in module chromes. Short of stuffing properties into $module object there isn't much else you can do.

1
  • Thanks for the workaround. I managed to pass a parameter with : use Joomla\CMS\Helper\ModuleHelper; $module = ModuleHelper::getModule('mod_custom','Module name'); $module->displayFull = true; $module = ModuleHelper::renderModule($module); and then accessing it with $module->displayFull; in the module overide.
    – web-tiki
    Aug 1, 2023 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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