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

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

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);

Joomla 2.5 render com_content component output

is it possible to render Joomla content from external script? For example I have some html string, which I want to pass to com_content component, to make all content plugin and module features available. I think I should use JDocumentRendererComponent class. Code in my external file:
<?php
require_once ('framework.php'); //loading joomla framework
jimport('joomla.document.html.renderer.component');
$contentHtml = '<p>Some content html</p>';
echo JDocumentRendererComponent::render('com_content',array(),$contentHtml);
?>
What I get is error on the last line:
Fatal error: Class 'JDocumentRendererComponent' not found...
What Im doing wrong? Any ideas?
It's because you haven't included the Joomla framework to the external script. Use the below code. This will ensure that the Joomla! environment is loaded correctly
/* Initialize Joomla framework */
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
/* Required Files */
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
/* To use Joomla's Database Class */
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
/**************************************************/
// Your code starts here...
// Remember that the Site application isn't running, so you cannot access $mainframe or any of its methods.
/**************************************************/
JDocumentRendererComponent Class is located in located in /libraries/joomla/document/html/renderer/component.php if you correct load the framework everything should work fine.
I found other solution for my question. The job can be also done by content plugin events (triggers). The piece of code from components/com_content/views/article/view.html.php:
JPluginHelper::importPlugin('content');
$results = $dispatcher->trigger('onContentPrepare', array ('com_content.article', &$item, &$this->params, $offset));
$item->event = new stdClass();
$results = $dispatcher->trigger('onContentAfterTitle', array('com_content.article', &$item, &$this->params, $offset));
$item->event->afterDisplayTitle = trim(implode("\n", $results));
$results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.article', &$item, &$this->params, $offset));
$item->event->beforeDisplayContent = trim(implode("\n", $results));
$results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.article', &$item, &$this->params, $offset));
$item->event->afterDisplayContent = trim(implode("\n", $results));
So we can actually make an object from our string and pass it to these triggers. As a result we are getting content rendered like an article, with its major functionality.
Some more info about it:
http://www.inmotionhosting.com/support/edu/joomla-25/create-plugin/content-plugin-events
https://groups.google.com/forum/#!msg/joomla-dev-cms/VZVurjiZWIs/9Vr45KS2LTMJ

how we get a module parameter in a component view in 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

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