how we get a module parameter in a component view in joomla - joomla

How do I get the module parameter inside a component in Joomla 1.5? I am using this code but it displays an empty result.
jimport( 'joomla.application.module.helper' );
$module = &JModuleHelper::getModule( 'mod_used_car_image');
$params = new JParameter($module->params);
print_r($params);

I got the params value. Use this code to get it:
jimport( 'joomla.html.parameter' );
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mod_name');
$moduleParams = new JRegistry();
$moduleParams->loadString($module->params);
$position = $moduleParams->get('position', '1');

You need to call the 'name' of your module, not the 'type' of module.
Let's say you named your module 'Used Car Image', your code should be:
jimport( 'joomla.application.module.helper' );
$module = &JModuleHelper::getModule( 'Used Car Image');
$params = new JParameter($module->params);
print_r($params);
Here's the manual:
http://docs.joomla.org/JModuleHelper/getModule

$module = JModuleHelper::getModule('modulename');
$params = new JRegistry($module->params);
var_dump($params);
That's how to use after joomla 3.0

Related

Render module in joomla

How do we render module in joomla with the title. Because now, I am able to render the module based on the position but it does not include the module title.
Here's how I render the module.
<?php
jimport('joomla.application.module.helper');
$modules = JModuleHelper::getModules('position-3');
foreach ($modules as $module) {
echo JModuleHelper::renderModule($module->title);
echo JModuleHelper::renderModule($module);
}
?>
Many Thanks.
Try this,
Using this method you can pass parameters to the module .
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$Module = JModuleHelper::getModule('mod_fmDataGrid');
$Params = "param1=bruno\n\rparam2=chris"; //This is the way of passing params values
$Module->params = $Params;
echo $renderer->render($Module);
Hope it helps..
Try using the following:
foreach ($modules as $module)
{
echo $module->title;
echo JModuleHelper::renderModule($module);
}
You can also use the following, however you will have to manually enter the module title. This is only assuming you don't want it to be dynamic. You will also need to change mainmenu
$module = JModuleHelper::getModule( 'mainmenu', 'Module Title Goes Here' );
echo JModuleHelper::renderModule( $module );
Try this.
Hope this will work for you.
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$contents = '';
$db = JFactory::getDBO();
$db->setQuery("SELECT * FROM `#__modules` WHERE id = 'your module id'");
$modules = $db->loadObjectList();
$module = $modules[0];
$contents = $renderer->render($module);

Send params to Joomla module

I write custom module, for example, when module called with parametr 1, module return 1, when called with 2, return 2 e.t.c.
But I cant find any documentation, how to send parametrs from page to module. Its how I call module now:
jimport( 'joomla.application.module.helper' );
$modules = JModuleHelper::getModules('NAME_OF_CUSTOM_POSITION');
$count_array = count($modules);
if ($count_array >0)
{
$attribs['style'] = 'xhtml';
echo JModuleHelper::renderModule( $modules[0], $attribs );
}
?>
But I don't know how to send params nor how to recieve them in my module.
I have used below code in one of my custom component.And it worked for me.
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$params = array('style'=>'xhtml');
$contents = '';
foreach (JModuleHelper::getModules('NAME_OF_CUSTOM_POSITION') as $mod) {
$registry = new JRegistry();
$registry->loadString($mod->params);
$registry->set('paramname','paramvalue');
$mod->params = (string)$registry;
$contents .= $renderer->render($mod, $params);
}
echo $contents;

How to get Module params in component area in joomla2.5

I want to get the module params in component area in joomla 2.5
Here my code :
jimport( 'joomla.application.module.helper' );
$module = &JModuleHelper::getModule('mod_module');
$moduleParams = new JParameter($module->params);
print_r( $moduleParams );
I try to print the $moduleParams...Its display nothing.I got this code from the website http://www.themepartner.com/blog/25/retrieving-plugin-module-component-and-template-parameters/
Is there anyother way to get the params using the module name.
for joomla 1.6 and higher
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mod_name');
$moduleParams = new JRegistry();
$moduleParams->loadString($module->params);
$param = $moduleParams->get('paramName', 'defaultValue');
Hope this help cause jparameter is deprecated in j1.5 higher
You missed the actual link i think for 1.7 is http://www.themepartner.com/blog/56/get-joomla-17-plugin-module-component-and-template-parameters/
For Joomla 3 you just need to do:
$module = JModuleHelper::getModule('mod_name');
$moduleParams = new JRegistry($module->params);
$param = $moduleParams->get('param_name', 'default_value');
I found the mistake
here the correct code
jimport( 'joomla.application.module.helper' );
jimport( 'joomla.html.parameter' );
$module = &JModuleHelper::getModule('mod_randomads');
$moduleParams = new JParameter($module->params);
Problem is jimport( 'joomla.html.parameter' ); is missed

JModuleHelper::getModules returns an empty array when SEF enabled only

I am using joomla 1.5. in this i have to include a module so i am using the code
$modules =& JModuleHelper::getModules('left1');
foreach ($modules as $module)
{
echo JModuleHelper::renderModule($module);
}
It returns an array value when SEF is disabled. but returns an empty array when SEF is enabled.I am totally confusing with this. Could anyone help me ?
If you would like to render modules loaded at position left1 use below code
$position = 'left1';
jimport( 'joomla.application.module.helper' );
if(JModuleHelper::getModules($position)) {
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('modules');
$options = array('style' => 'xhtml');
return $renderer->render($position, $options, null);
}

Render a Joomla 2.5 Menu Module with some PHP

Trying to use this code to render a menu module on a custom template
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule( 'menu' );
$attribs = array('style' => 'mainnav');
$module->params = "menutype=" .$mainmenu ."\nshowAllChildren=1";
echo JModuleHelper::renderModule($module, $attribs);
The menu only works if I have another menu module published, so I am sure this only needs a line of code to make it work without having to publish a menu module.
The menu exists, the module for this menu does not exist, I am trying to create it with this code.
Please help.
The code works fine I just had a small correction to make:
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule( 'mod_menu' );
$attribs = array('style' => 'mainnav');
$module->params = "menutype=" .$mainmenu ."\nshowAllChildren=1";
echo JModuleHelper::renderModule($module, $attribs);
on the second line, the call should be to "mod_menu" and not just "menu", and this makes the code to work perfect :)
Why don't just use the include module?
<jdoc:include type="modules" name="mainnav" style="mainnav" />
This will allow you to publish whatever module you wan't in that position.
Otherwise the getModule function works like this:
JModuleHelper::getModule( 'position', 'title' );
According to the Joomla! API so you need to pass both parameters.
i use this code to render other module by id
$mod_id = $params->get('mod_id');
if ($type == 'logout' && $mod_id != ''){
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$db =& JFactory::getDBO();
if ($jVersion=='1.5') {
$query = 'SELECT id, title, module, position, params'
. ' FROM #__modules AS m'
. ' WHERE id='.intval($mod_id);
} else {
$query = 'SELECT id, title, module, position, content, showtitle, params'
. ' FROM #__modules AS m'
. ' WHERE m.id = '.intval($mod_id);
}
$db->setQuery( $query );
if ($mod = $db->loadObject()){
$file = $mod->module;
$custom = substr( $file, 0, 4 ) == 'mod_' ? 0 : 1;
$modu->user = $custom;
// CHECK: custom module name is given by the title field, otherwise it's just 'om' ??
$mod->name = $custom ? $mod->title : substr( $file, 4 );
$mod->style = null;
$mod->position = strtolower($mod->position);
echo $renderer->render($mod, array());
}
}
use this, 100%, render modules at this position.
<?php
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('modules');
$options = array('style' => 'xhtml');
$position = 'article-banners';
echo $renderer->render($position, $options, null);
?>
$position refer to module position, may be more than one...
$style - none, rounded, xhtml...

Resources