I had previously added Joomla modules from within Joomla articles this way : {loadmodule mod_name}
but this time I need to pass parameters from it.
How can I pass parameters from within the article to a Joomla module?
You'll need to modify or clone the Joomla plugin loadmodule
because it doesn't handle parameters other than just a module name. It's not particularly difficult to do if you're proficient in PHP (assuming you don't mind getting your hands dirty with a little bit of Regex work) but I'd suggest cloning it and using it this way:
\plugins\content\loadmodule
to \plugins\content\Myloadmodule
(and all it's files)loadmodule.php
and loadmodule.xml
to myloadmodule.php
and myloadmodule.xml
. These are the files you'll do all the work on.loadmodule
with myloadmodule
, (Case sensitive)myloadmodule.php
, start at around line 36 with the Regex that strips out what is in the {loadposition xxx}
being processed. You'll need to tinker with this Regex to get the parameters that you want to supply when using {myloadmoduel blah-blah-blah}
in your article.loadposition
and create and identical record for myloadposition
. (Unless you want to write and installer)I think I've covered it all, but this should be enough to get most of it done for you. When you're done, use {myloadposition ...}
instead of {loadposition ...}
.
I will give more details about the previous answer, to be able to pass parameters to a module with a tag as {loadmodule mod_name,param} The solution given by GDP works fine: it's easy and quick to rewrite a content plugin (e.g. myloadmodule), following the steps 1 to 5 in the previous answer. The problem, for me, comes with the steps 6: how to put parameters into the module, and ohow to retrieve de parameters within the module.
Step 7 : how to give parameters to the "render" of a module
In the plugin created (base on the loadmodule), you have to find the lines with the following code :
echo $renderer->render($module, $params);
Before this line, you can put parameters into the $params parameter, but "render" of the module retrieves only params with the key 'params', using a json format. So, to pass parameters to the render function, you can do something like that :
$param = array('param_name' => 'value'); // param_name = value
$params = array('params' => json_encode($param)); // 'params' (String) should be decoded by the render of the module
echo $renderer->render($module, $params);
Step 8 : How to retrieve the parameter within the module
In the helper of your module, you can retrieve the parameter with $params variable :
$value = $params->get('param_name');
To understand a helper, read this tutorial : http://docs.joomla.org/J3.3:Creating_a_simple_module/Developing_a_Basic_Module
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With