我的智能模板中有一个div,我想通过ajax调用PHP文件,它将获取/显示另一个模板文件。这将包含将要订购的网站上的页面列表,您可以单击向上/向下箭头对其进行重新排序,因此我需要在每次单击后重新加载相同的模板。
这可能吗?
<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 :(得分:0)
你必须在ajax响应文件中创建一个新的智能对象,请注意,您必须在此文件中包含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;