1

I created a custom mod_helloworld module, according to the instructions in the Joomla 3 documentation. I have a "lang" parameter on the mod_helloworld.xml config section.

The module is loaded inside an article using {loadmodule mod_helloworld, "mytestmodule"}

In the mod_helloworld.php I can't get the "lang" parameter value out using

$language = $params->get('lang').

Also var_dump($params) and var_dump($module) give pretty empty results.

I have managed to get the results using:

jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule( 'mod_helloworld', 'mytestmodule' );
$params = new JRegistry($module->params); 

But, I don't think this should be necessary inside the "current" module.

Also tried this by duplicating an existing standard joomla module and changing its name. Same effect, although the original works fine.

If I load the module somewhere else on a page, like in some template position, it works fine, but not when loaded inside an article. Yet the existing "standard" joomla modules work fine also when loaded inside an article.

What's wrong here?

3
  • $language = $params->get('lang') should work fine. Did you save the module parameters in the backend? I am not sure if this is needed once at all but it can't hurt
    – fruppel
    Jul 30, 2015 at 20:53
  • Couple you please show us the code for the parameter in the XML file? Might be a silly question, but are you sure you have the module enabled?
    – Lodder
    Jul 30, 2015 at 20:56
  • I edited my question a bit after realizing the problem occurs only when loading the module inside an article. And yes, parameters are saved in the backend ok. And the module is enabled. Works fine if loaded in a position, but not when loaded inside an article. Although, the other existing modules work fine also when loaded inside an article. Jul 30, 2015 at 21:05

1 Answer 1

1

Create a module and set its position to myposition. myposition can be any value that doesn't conflict with an existing template position. Type in the position myposition and press enter instead of selecting it from the drop-down list.

Assign the module to All the Menu Items. This will make sure that it always appears, no matter how the visitor got to the article. The module will not show unless you put the command to load the module in an article.

Edit the articles where you want this module to appear and insert the text {loadposition myposition} in the article at the place where you want the module.

3
  • Thanks. The key here was using loadposition instead of loadmodule. That solved it. I still don't understand why loadmodule doesn't work. Any idea of the reasons behind? Jul 31, 2015 at 9:14
  • loadposition allows you to publish all the modules in a particular position. loadmodule allows you to publish just one particular module. Jul 31, 2015 at 10:00
  • Sure, I understand that. Still it doesn't explain why $params and $module are not populated when using loadmodule. Aug 1, 2015 at 19:05

Your Answer

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

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