繁体   English   中英

如何使用Ajax Joomla加载模块

[英]How to load a module with Ajax Joomla

我正在使用joomla模板,其中使用以下jquery函数通过菜单项将html / php页面动态加载到内容div中。

$page.load($lnkLoc);

该链接会加载一个单独的页面,该页面显示如下内容。

    <div class="contentarea">
<jdoc:include type="modules" name="page2cont1" title="Page two top" />
</div>
<div class="contentarea">
<jdoc:include type="modules" name="page2cont2" title="Page two middle" />
</div>
<div class="contentarea">
<jdoc:include type="modules" name="page2cont3" title="Page two bottom" />
</div>
<footer>
<jdoc:include type="modules" name="footer" title="Footer" />
</footer>

但是,尽管一切正常,但joomla模块不会显示,而是在html中列出了以下内容

<div class="contentarea"><jdoc:include type="modules" name="page2cont1" title="Page two top"></jdoc:include>

唯一可以加载的是页脚模块,因为它已存在于初始页面加载中。 我究竟做错了什么? 我在尝试不可能的事吗?

单独的页面应该是一个PHP文件,在呈现模块之前,该文件需要一些Joomla文件。 下面的代码应该工作:

<?php
// Name of this file: loadmodule.php

define( '_JEXEC', 1 ); // This constant is required by all Joomla files.

// The JPATH_BASE should be defined as the path to the root Joomla installation.
define( 'JPATH_BASE', '<path to joomla root directory>' );
define( 'DS', DIRECTORY_SEPARATOR );

// Those requires below will allow us to use Joomla's instructions.
require_once ( JPATH_BASE .DS. 'includes' .DS. 'defines.php' );
require_once ( JPATH_BASE .DS. 'includes' .DS. 'framework.php' );

// Instantiate Joomla to be able to use it.
$mainframe =& JFactory::getApplication('site');

// Loading and rendering the module.
$modules = JModuleHelper::getModules('testloadmodule');
foreach( $modules as $module ) echo JModuleHelper::renderModule($module);
?>

像这样的简单jQuery加载指令就可以加载呈现模块的文件: $('#module_container').load('loadmodule.php');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM