用jQuery加载Smarty TPL [英] Load smarty tpl with jquery
问题描述
我想用jQuery在div内加载一个聪明的tpl部分,我得到了:
i would like to load a smarty tpl partial inside a div with jquery, i got:
js:
function load_new_partial() {
jQuery("#ajax_zone").fadeIn('slow').load('/views/partials/partil.tpl');
}
在tpl调用方内部:
<a href="#" onclick="load_new_partial();">{$language_array.lang_new_campaign}</a>
<div id="ajax_zone">initial div yadadada</div>
称为tpl:
{$user_name_smarty}{$account_array}
我在单击时显示partial.tpl没有问题,问题是加载的partial.tpl似乎没有得到我已经分配给smarty的任何变量.
I have no problem displaying partial.tpl on clicked, problem is that loaded partial.tpl doesn't seem to get any of the variables i had already assigned to smarty.
我在做什么错?我该如何加载部分代码并使其能够访问已经建立的smarty变量?
What am i doing wrong?, how do i load a partial and make it have access to the already established smarty variables?
$smarty->assign('user_name_smarty', $user_name_smarty);
谢谢.
推荐答案
如果像这样加载它,则将其作为文本文件加载.您希望它请求使用该TPL作为模板的PHP文件.
If you load it like this, you are loading it as a text-file. What you want it to request a PHP file, that uses that TPL as a template.
通常:
- 请求PHP
- 解析TPL(对变量进行处理)
- 制作html
- 在浏览器中显示
现在:
- 请求PHP
- 解析TPL(如果PHP使用tpl)
- 制作html
- 在浏览器中显示
- 浏览器解析JQuery
- 加载额外的tpl(不会被解析!)
如您所见,加载额外的tpl后没有"parse tpl"提示
As you can see, there is no "parse tpl" stap after you load the extra tpl
您可以使用ajax请求一个PHP文件,并将该请求的结果添加到div中.
You could request a PHP file with ajax, and add the result of that request to your div.
这篇关于用jQuery加载Smarty TPL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!