如何在组件 joomla 2.5 中调用模块时设置布局



在组件中如何调用模块:

tmpl
---default.php
---hello.php
mod_hello.php
mod_hello.xml
helper.php    
$module = JModuleHelper::getModule('mod_hello');
echo JModuleHelper::renderModule ($module );

当我使用布局default echo结果时,如何显示模块mod_hello的布局hello

布局

阅读下面的论坛主题,这可能会对您有所帮助

http://forum.joomla.org/viewtopic.php?f=544&t=356176

$modules =& JModuleHelper::getModules('mod_hello'); 
foreach ($modules as $module) 
{ 
echo JModuleHelper::renderModule($module); 
} 

$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('modules');
$options = array('style'=>'raw');
echo $renderer->render('mod_hello',$options,null);

有两种调用模块的方法:

在内容/文章中调用模块:您可以使用{loadposition position}(感谢plgContentLoadModule -/plugins/content/loadmodule.php)

以编程方式调用模块(模块调用另一个模块或组件调用模块):

A. Call Module by position :
$position = 'left';
$contents = '';
foreach (JModuleHelper::getModules($position) as $mod) {
$contents .= $renderer->render($mod, $params);
}
B. Call Module by name :
$modName = 'mostread '; // not mod_mostread 
$modTitle = 'Popular';
$mod = JModuleHelper::getModule($modName, $modTitle);
$content = JModuleHelper::renderModule($mod);

我是如何做到的:

模块的上下文中有一个$attribs数组,因此您可以使用它来传递布局

$module = JModuleHelper::getModule('mod_hello');
$attribs = array('layout'=>'hello');
echo JModuleHelper::renderModule ($module,$attribs);

之后在mod_hello.php:

$layout = isset($attribs['layout'])?$attribs['layout']:'default';
require(JModuleHelper::getLayoutPath('mod_hello',$layout));

最新更新