how to pass parameters to joomla module loaded from article - joomla

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:
Copy folder \plugins\content\loadmodule to \plugins\content\Myloadmodule (and all it's files)
Within the new folder, rename loadmodule.php and loadmodule.xml to myloadmodule.php and myloadmodule.xml. These are the files you'll do all the work on.
In both files, replace occurrences of loadmodule with myloadmodule, (Case sensitive)
In 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.
Find the database entry in your table '_extensions' for loadposition and create and identical record for myloadposition. (Unless you want to write and installer)
Finally, you'll need to render the modules with your new parameters - I can't begin to help there because I don't know what modules, or parameter work you'll be doing, but this renderModule documentation will be of assistance.
7.
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

I googled the same issue and found your question. I know its old but my find may help someone else. There are now plugins that allow embedding modules and allowing you to pass parameters to it. My choice is Module Plant.

Related

Bitrix CMS, how to get cached data based on GET parameter in template of standart component?

I'm working with a component bitrix:catalog (which is standard one) and faced an issue. I want to add some extra GET parameters to switch view mode. I think there is no need to rewrite whole component to make such switcher, so I added extra keys in result_modifier in a way similar to:
$this->__component->arResultCacheKeys = array_merge($this->__component->arResultCacheKeys, array('key1', "key2"));
Earlier in the same result_modifier I perform adding those extra keys in $arResult['key1'] etc. They seem to be correctly saved, but only for current inquiry such as ?view=list or view=card, that means only one variable value is saved and it does not react on changing of GET parameter. Is there simple and correct way to make that component to cache and to output data based on GET variable? The only idea which came to my mind is to rewrite component by adding extra parameter and checking of GET, but I think there must more simple and correct solution to make in via template. Human Readable Links are turned on. And I want to have auto-cash being turned on as well. If I turn it off it starts working as planned.
One of possible solutions is to rewrite it cache by SetTemplateCachedData but it still seems to me rough and incorrect way for such simple task.
Bitrix masters please help me to find correct solution, google can't help at the moment.
If you use standard bitrix:catalog component, you may be use standart bitrix:catalog.section. In that component.php used standart component cache.
That means you can describe additional parametr in you custom .parameters.php, and set it in bitrix:catalog.section params.
Standart component cache set cacheId based on arParams.
So you include component should look like this:
$APPLICATION->IncludeComponent(
"bitrix:catalog.section",
"",
array(
"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
"IBLOCK_ID" => $arParams["IBLOCK_ID"],
"ELEMENT_SORT_FIELD" => $arParams["ELEMENT_SORT_FIELD"],
"ELEMENT_SORT_ORDER" => $arParams["ELEMENT_SORT_ORDER"],
....
....
"NEW_ADDITIONAL_GET_PARAMS"=> $_GET['view']
),
$component
);
Of course better way somethink like
"NEW_ADDITIONAL_GET_PARAMS"=> (in_array($_GET['view'],array('list','card'))?$_GET['view']:'list')
But may be you need just set right catalog params: SEF_MODE SEF_FOLDER SEF_URL_TEMPLATES

Smarty getting page content

I need to edit a page on prestashop, I've found that code
<ul id="idTab2" class="bullet">{$agencies->content}</ul>
And where should i search for that $agencies variable ?
I have found the text which is being displayed into that place in CMS.
However I'd that variable need to be define somewhere, am I right ? Anyone knows where should i search for that ? I'm new to prestashop.
Why am i asking for this ? I need to add another page for example
<ul id="idTab2" class="bullet">{$test->content}</ul>
- but I can't just simply add another page called test.
The {$agencies} variable is being set in a object derived from either the Controller or Module classes but to be honest it looks like you're working with code that has been customised (via a class override or a module) making it impossible to provide a definitive answer to your question without knowing more detail.
If you can locate the term 'agencies' in a file located under \controllers, \modules or \override in your installation, then you will be closer to finding your answer. It will be contained in a function call similar to:
$this->context->smarty->assign('agencies' , [some-variable]);
Note that the parameters to the function may also be passed as an array for multiple assignments.

How can I change the execute order for Magmi plugins?

I'm working on importing (on a regular basis) about 6,000 items into Magento using Magmi. I've got nearly everything configured the way I need it, but I have one issue.
I need to concatenate 3 columns from my .csv file to create a "category_ids" column. I'm using the Value Replacer plugin with the following value:
{item.departmentid},{item.classid},{item.subclassid}
This works well, however I need to then map this field to another field using the Generic Mapper plugin. Both functions work individually, however I need the Value Replacer to run BEFORE the Generic Mapper. As best as I can tell, it appears the Generic Mapper runs first. Is there a way I can alter the execute order for these two plugins?
Thanks for the help!
Update for Dweeves:
Doh! I totally overlooked that section while trying to figure this out. Now that I've gone through it, I might need a little more help. Right now I've using just the Value Replacer plugin with the following settings:
Replaced attributes: category_ids
New value for category_ids:
{{ ValueRemapper::use_csv('/var/www/magmi/category_ids.csv')->map({item.departmentid},{item.classid},{item.subclassid}) }}
It doesn't seem to be working as I intended it to, but I'm a systems guy and not a PHP programmer. Any help?
2nd Edit
I got it working by using the Value Replacer function to first concatenate everything into a new "test" column, then using the Value Replacer Value Mapper function to create the category_ids column with the mapped values. Confusing, but it's working well.
You can use the ValueRemapper helper of Value Replacer plugin for this kind of purpose.
See Value Replacer Plugin Documentation (ValueRemapper helper section)
To answer your original question (how to define the order the plugins run in).
From my experience, the plugins are loaded in order of their plugin filename.
For example, if you look at magmi/plugins/base/itemprocessors/importlimiter, you will notice that the filename for the plugin is 01_importlimiter.php.
If you look in the genericmapper plugin folder, you'll notice the plugin filename to be 02_genericmapper.php.
With this being said, 01_importlimiter.php will execute before 02_genericmapper.php.

loadByRequestPath() is Overriding Parameter With Current URL Path

I am trying to load a rewrite rule based on a product's URL path.
I am using the loadByRequestPath() method in Mage_Core_Model_Url_Rewrite to accomplish this. However, no matter what I supply this method I get the following result (Check comment in code):
public function loadByRequestPath($path)
{
Zend_Debug::dump($path); // returns the path to my module
$this->setId(null);
$this->_getResource()->loadByRequestPath($this, $path);
$this->_afterLoad();
$this->setOrigData();
$this->_hasDataChanges = false;
return $this;
}
Here is my module code:
$productRewrite = Mage::getModel('core/url_rewrite') ->loadByRequestPath($product->getUrlPath());
Oddly, I get this back:
Array ( [0] => rewrites/getProductRewrites
[1] => rewrites/getProductRewrites/ )
Array ( [0] => 01003-product-name )
So loadByRequestPath() is getting called twice for whatever reason. $productRewrite still returns an empty object.
I have verified that $product->getUrlPath() returns the correct path. (As seen in the second array)
I am on Magento 1.6.1.
Your question is still a little unclear, so this answer might not address the specific problem you're seeing.
Magento's core team hasn't done a great job of communicating these sorts of things over the years, but loadByRequestPath is one of those methods that's best thought of as a "private api". Not in the OOP sense, but in the "this is a method used to implement core system functionality, and probably won't work like you think it should work, so use at your own risk".
The PHP code you're trying to use
$productRewrite = Mage::getModel('core/url_rewrite') ->loadByRequestPath($product->getUrlPath());
won't work with a default installation of Magento because the rewrite object doesn't have a store ID set. Trying something like this should work. (assuming the sample data, with an installed store object that has an ID of "1" and that the product in question exists in that store)
$productRewrite = Mage::getModel('core/url_rewrite');
$productRewrite->setStoreId(1);
$productRewrite->loadByRequestPath($product->getUrlPath());
The loadByRequestPath method assumes that a rewrite already has a store ID set, as it's part of Magento's larger dispatching process. (self-link to article describing the role of rewrites in Magento's routing system)
All that said, the problem you're describing is somewhat confusing. You say that
Zend_Debug::dump($path);
returns
an array that contains the path to my module
While I'm sure you know what the phrase "path to my module" means, it's a meaningless term in the larger magento universe. Being more specific about the literal value will help people understand what you mean.
Additionally, you also say
I have verified that $product->getUrlPath() returns the correct path.
but you're not clear on the value of "the correct path".
My guess would be the path you're seeing in Zend_Debug::dump is the call that's coming through as a part of the standard dispatch and not your later call using $product->getUrlPath(). However, the lack of clarity in your question makes that hard to tell.
If setting the store ID doesn't get you what you want, update your question with a full explanation of how you're running your code, and what you see displayed. With that information more people will be able to help you.

Can a Joomla module "know" what position it's in?

I'm fairly new to Joomla (I've been more of a Wordpress guy) and I have a question about module positions.
Can a module know what position it's in. For instance can I do something like this:
if(modulePosition =='left'){
Do this...
}else{
Do that...
}
It seems easy enough, but I've searched for hours and can't find anything that will help me with that. I know there is a countModules function but from what I can tell, that just checks to see if the module is active or not.
Thanks for your help!
I found the answer! Mostly thanks to #Hanny. His idea of using the modules id got me googling for that and I came across the answer. For anyone else that happens to be looking to do something similar here it is.
You use a global variable $module (who'd a thought, right?)
So my code now looks like this:
$class = '';
if($module->position == 'position1'){
$class = 'class1';
}
and so on...
Pretty simple, huh?
To find out what else you can do with the global variable $module just put this in your code and see what info you can use:
echo(print_r($module));
Thanks for all your help!
The short answer is 'yes', you'll assign a module a position based on your template. When it shows up you can have conditionals like that regarding that position (different templates have different naming conventions for positions, so make sure you know what they are before coding).
For example, some use "Position12", others may use "leftcol", etc. You just have to check in the template files to see (you can check the .xml file in the template directory to see the positions listed in the template, or look in the index.php file for the jdoc includes).
In some of my experience, the only time you'll really ever need code like that is in the core layout files of the template (for example, if you have different widths of columns depending on modules being present or not), otherwise there won't really be a time where you 'may or may not' have a module showing up - because you'll explicitly be telling them where to be and when on the back end.
I tried to comment under john's solution but I don't have a enough rep points-- I wanted to add it doesn't matter what you name the module position in your template case-wise the position name you get back from $module->position is always all lowercase regardless of how you named the position in the template... ie. in your template xml somewhere you might have topBar position will be named 'topbar' not 'topBar' when you try to check it with
if($module->position == 'topBar') //always false... use instead
if($module->position == 'topbar') //what you need to use
I'm going to disagree with Hanny. I think the answer is no, not as you describe.
The template knows when it has reached a module position, and it gets a list of modules assigned to that position, then calls for them to be rendered. But it doesn't pass that information on. It's not stored in JApplication or JDocument etc either (like, nothing stores where in the template the rendering is up to or anything).
There are some hacky ways to almost get what you want though. If you know the template positions you need to search (sadly there's no easy method for getting this from the template - otherwise you could parse your template's .XML file for <position> elements...), then you could do something like:
<?php
$positions = array('left', 'right', 'top', 'bottom')
$found_in = false;
foreach ($positions as $cur_position)
{
$module_positions = JModuleHelper::getModules($cur_position);
foreach ($module_positions as $cur_module_in_pos)
{
if ($cur_module_in_pos->module == 'mod_MYMODULE')
{
$found_in = $cur_position;
}
}
}
if ($found_in)
...
Of course, this doesn't work well if your module is included multiple times on the page, but maybe that's an assumption you can make?
Otherwise it'd be up to hacking the core - you could use a JDispatcher::trigger() call before the template calls a module, set some var etc. Unfortunately there's no such event in core to start (a pre_module_render or something).
A module instance is assigned to a single position and this is stored in the database and normally you would style the position in the template. A module instance can only be assigned to one position. So while it's an interesting question, it's not really a practical one.
The exceptions to this are the following:
loadposition ... you might want to know if a module is being loaded using the plugin because this would put it potentially somewhere besides the styled area for the position. THough i would recommend always making a new instance for this precisely so you have more control.
loadmodule ... module loaded by name using the plugin. In this case again you are probably better off making a new instance of the module and styling it. Also I'd put it in a span or div anyway, depending what it is.
jdocinclude:module ... loading a module directly in a template. Again if you are doing this I would wrap it in a span or div. In this case you are also allowed to include a string of inline styles if you like that kind of thing.
Rendering the module to a string and echoing it, again that is basically a very customized solution and you would want to set the styles and options.

Resources