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);
Related
On my k2 pages I needed module complete on the top area, a module assign is not possible because the pages are dynamicly from the DB selected. So I installed a module like "loadmodule", the difference is simple I can get module with specific id.
For example: {loadmodulefromarticle|97} if I use it in the extra fields or in the content area then it works, but as written I need it in the top area of my page, so I have an if request and try load k2 content on the top. I get content and that's ok. But I see here only plain text and the module is not loaded. My question is, what is to insert here so that I get the module loaded? I think it can be something around to $result;
<?php
$menuID = JSite::getMenu()->getActive()->id ;
if ($menuID == '713') {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('introtext');
$query->from('#__k2_items');
$query->where('id = ' . JRequest::getInt('id'));
$db->setQuery($query);
$result = $db->loadResult();
?>
<div id="gkHeaderMod">
<div><?php echo $result; ?></div>
</div>
<?php
}
?>
You could do something like the following. It uses Joomla coding standards to get the menu ID and renderModule to display the module.
<?php
$app = JFactory::getApplication();
$menuID = $app->getMenu()->getActive()->id;
if ( $menuID == '713' ) {
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('introtext')
->from('#__k2_items')
->where('id = ' . JRequest::getInt('id'));
$db->setQuery($query);
$result = $db->loadResult();
echo '<div id="gkHeaderMod">';
$module = JModuleHelper::getModule( 'mod_example', 'Module Title' );
echo JModuleHelper::renderModule( $module );
echo '</div>';
}
?>
Note that you will have to change mod_example and Module Title to whatever you require
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;
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);
}
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...
I am use following code to retrieve the session variable in routes.php
if($this->db_session->userdata('request_url')!="")
{
$route['user/(:any)'] = "search_user_name/redirect_url/".$_SESSION['request_url'];
$this->db_session->unset_userdata('request_url');
}
else {
$route['user/(:any)'] = "search_user_name/index/$1";
}
the session variable would be set into template/header.php
$this->db_session->set_userdata('request_url', $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
You can not use db_session in routes.php because routes.php is parsed before db_session is loaded.
Maybe you should create a base controller and redirect from the constructor of the base controller.
Correct me if iam wrong.
You can use hooks.
Codeigniter user guide hooks
You can use database in routes and put your routes url in database.
Here is an example:
require_once( BASEPATH .'database/DB'. EXT );
$db =& DB();
$table2 = $db->dbprefix.'lang';
$query2 = $db->get( $table2 );
$result2 = $query2->result();
foreach( $result2 as $row )
{
$fields = $db->list_fields($table2);
$findme = 'code';
foreach($fields as $field):
$pos = strpos($field, $findme);
if($pos !== false and $row->$field != ''):
$route[''.$row->$field.''] = 'main/setlang/$1';
endif;
endforeach;
}