2011-11-24 124 views
0

我在我的smarty模板中有一個div,我想通過ajax調用一個PHP文件來獲取/顯示另一個模板文件。這將包含網站上的一個頁面列表,這些頁面將被排序,您可以點擊向上/向下箭頭對它們進行重新排序,因此我需要它在每次點擊後重新加載相同的模板。在另一個模板中使用ajax調用/重新加載smarty模板

這可能嗎?

<div id="pagelist_container"></div> 
<script type="text/javascript"> 
    {literal} 
    $(document).ready(function(){ 
     $("#pagelist_container").load("path_to_file/pages.php"); 
    }); 
    {/literal} 
</script> 

然後pages.php是:

$smarty->display('ajax/pages.tpl'); 

每當我把智者行我得到一個500錯誤。

+0

你能寫出錯誤嗎? – VMAtm

回答

0

必須在您的ajax響應文件中創建一個新的smarty對象,請注意您必須在此文件中包含Smarty.class.php。這是path_to_file/pages.php的內容:

// include smarty (assuming you have smarty in your path) 
require_once('Smarty.class.php'); 
// initialize smarty 
$smarty = new Smarty(); 
// setup cache, template_c & templates directory 
$smarty->templates_c = "templates_c"; 
// assign any variables to smarty here 
$smarty->assign('<variable>', $variable); 
// fetch output for your pages 
$output = $smarty->fetch('ajax/pages.tpl'); 
// return the content of the template to ajax caller 
echo $output;