Templates Smarty包括php和javascript中的模板(使用Smarty和JSmart)
我尝试在PHP和JavaScript中使用一个smarty模板。这非常有效,但我正在试图弄清楚,当JavaScript端需要元素ID而PHP端需要文件路径时,如何在模板中使用{include file=”“}标记Templates Smarty包括php和javascript中的模板(使用Smarty和JSmart),templates,include,smarty,Templates,Include,Smarty,我尝试在PHP和JavaScript中使用一个smarty模板。这非常有效,但我正在试图弄清楚,当JavaScript端需要元素ID而PHP端需要文件路径时,如何在模板中使用{include file=”“}标记 元素id必须与我在PHP端使用的路径匹配吗?好的,我研究了如何做到这一点,我为jsmart重写了JSPrototype方法,该方法通过id请求模板: jSmart.prototype.getTemplate = function () {}; // Add your method he
元素id必须与我在PHP端使用的路径匹配吗?好的,我研究了如何做到这一点,我为jsmart重写了JSPrototype方法,该方法通过id请求模板:
jSmart.prototype.getTemplate = function () {}; // Add your method here
这样,我可以控制如何处理id,包括将其映射到具有与传递路径不同id的模板元素。我知道这个问题看起来很老,但我想回答您的问题,因为我是通过Google遇到这个问题的,可能会遇到其他许多问题 xyz.tpl-要包括的模板
Hello {$name}
pqr.tpl-父模板
There you see the message
{include file='./xyz.tpl'}
现在在网页的Javascript部分定义
jSmart.prototype.getTemplate = function (name) {
// Load template content here of template 'name' via ajax or DOM. Say here in the e.g. it would be './xyz.tpl'.
};
现在只需调用父模板
<script>
var tplData = <content of pqr.tpl>; // You can load data in this via ajax or from DOM.
var tplObj = new jSmart(tplData);
var output = tplObj.fetch({'name': 'World'});
alert(output);
</script>
var tplData=;//您可以通过ajax或从DOM加载数据。
var tplObj=新的jSmart(tplData);
var output=tplObj.fetch({'name':'World'});
警报(输出);
资料来源:-