1

在组件中如何调用模块:

tmpl
---default.php
---hello.php
mod_hello.php
mod_hello.xml
helper.php    

$module = JModuleHelper::getModule('mod_hello');
echo JModuleHelper::renderModule ($module );

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

4

2 回答 2

0

How I did it:

There is an $attribs array which is in the module's context so you can use it to pass the layout

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

And after that in mod_hello.php:

$layout = isset($attribs['layout'])?$attribs['layout']:'default';
require(JModuleHelper::getLayoutPath('mod_hello',$layout));
于 2012-12-15T15:07:02.920 回答
0

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

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

有两种调用 Module 的方法:

在 Content/Article 中调用模块:您可以使用 {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);
于 2012-10-17T05:13:42.683 回答