如何将此Joomla模块渲染到另一个位置而不会丢失与文章的连接

时间:2014-04-07 13:13:12

标签: joomla joomla-extensions joomla3.0

这是来自Joomla的Dizi-images模块(plugin / content / images / images.php)的代码。这样可行,它会在特定文章的末尾发布图像或图像库。

但是,如果我想将图像/图像库发布到另一个位置(通过更改其在Joomla admin中的位置和下面代码中的getModules值),它将失去与文章的“连接”。它显示在网站上的每篇文章中。

是否可以在下面创建此代码,以便能够将图像/图片库发布到其他位置,而不会失去与特定文章的连接?

/*
 * load front end images module
 */

public function onContentAfterDisplay( $context, &$row, &$params, $limitstart = null )
{
    $jinput = JFactory::getApplication()->input;
    $option = $jinput->get('option', '', '');
    $view = $jinput->get('view', '', '');

    if( $context == 'com_content.article' && ( $modules = JModuleHelper::getModules( 'images' ) ) )
    {
        return JModuleHelper::renderModule( $modules[ 0 ] );
    }

    return '';
}

由于

马格努斯

Screenshot of the modules that I change position on

我更改位置的模块的屏幕截图(Joomla Admin / Extensions / Module Manager /)

我使用的插件是“Dizi图片库”-extension。

The Dizi-tab in Article Manager. Where you add images to the article your in

这显示了Dizi-images选项卡。将图像/图片库添加到您的文章中的位置。

2 个答案:

答案 0 :(得分:1)

这三行代码将允许您根据需要加载和呈现任何现有模块。

jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mod_myimagemodulename', 'Images Gallery');
echo JModuleHelper::renderModule($module, array('style' => 'xhtml'));

如果要从后端进行管理,则需要使用不同的菜单位置分配复制现有模块。听起来像唯一的限制是源图像文件夹,所以模块不应该介意!

**编辑**

要创建一个像" right"这样的新位置,您需要在模板index.php中添加一个新的jdoc元素,您希望新的位置:

<jdoc:include type="moduels" name="right" style="xhtml" />

然后在模板清单XML文件中,将新位置添加到现有位置列表中:

<position>right</position>

现在,如果您导航到要放置的模块副本,则可以选择新创建的&#34;右键&#34;位置。

**编辑**

注意到模块实例的加载方式,名称应反映模块类型名称。

$modules = JModuleHelper::getModules( 'images', 'Images gallery' )

绝对是从JRequest迁移出来的。

答案 1 :(得分:0)

为什么不为另一个位置创建一个新的模块实例?这样,这个模块保持原样并且新模块在其他地方发布而不会与您拥有的代码冲突。

同意Lodder,使用JInput。