2015-07-10 112 views
0

我正在使用以下jquery函數通過菜單項將html/php頁面動態加載到內容div中的joomla模板上。如何使用Ajax加載模塊Joomla

$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> 

,做負載唯一上市是頁腳模塊,因爲它存在於初始頁面加載中。我究竟做錯了什麼?我在嘗試不可能的事情嗎?

+0

什麼是你加載文件的擴展名?它是PHP嗎? 你是否試過使用加載而不是jdoc語句? 例如:'

{loadposition page2cont1}
' – FlavioEscobar

+0

我會盡快嘗試。 –

+0

加載位置也不起作用,我嘗試了無數其他方法。我認爲唯一的選擇是通過PHP加載模塊。當你將新的html加載到index.php標記中時,它會忽略Jdoc和joomla通常會讀取的任何內容。 –

回答

1

您的單獨頁面應該是一個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');