如何结合 jQuery tmpl 和 Zend Views(避免代码重复)
我正在使用 jQuery.tmpl 模板来呈现通过 ajax 获取的数据。尽管如此,有时布局还是在服务器上呈现(即用于入口点、回退和缓存),因此 jQuery.tmpl 使用的模板与 Zend Framework 使用的视图非常相似。作为备份。
问题是 Zend 在 HTML 中使用 PHP 标签,而 jQuery 使用模板语言。
ZF 视图如下所示:
<div id="Item_<?= $this->item->id ?>" class="Items">
<h2><?= $this->item->title ?></h2>
<p><?= $this->item->teaserText ?></p>
</div>
jQuery 模板如下所示:
<div id="Item_${id}" class="Items">
<h2>${title}</h2>
<p>${teaserText}</p>
</div>
是否有一个易于集成但仍然灵活的模板引擎可以用来解析 jQuery 模板? 有没有人有使用 Smarty 实现此类解决方案的经验?
I am using jQuery.tmpl
Templates to render data that i fetch via ajax. Still, sometimes layouts are rendered on the server (i.e. for entry-points, fallback and caching) so the templates used by jQuery.tmpl
are very much the same as the Views used by Zend Framework which is use as a backup.
The problem is that Zend uses PHP tags inside HTML while jQuery uses a template language.
Where the ZF View looks like this:
<div id="Item_<?= $this->item->id ?>" class="Items">
<h2><?= $this->item->title ?></h2>
<p><?= $this->item->teaserText ?></p>
</div>
the jQuery Template looks like this:
<div id="Item_${id}" class="Items">
<h2>${title}</h2>
<p>${teaserText}</p>
</div>
Is there an easy to integrate but still flexible template engine i could use to parse the jQuery templates?
Has anyone any experience with using Smarty for such a solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以扩展 Zend_View 以使用与 jQuery 模板引擎相同的语法,这样两个模板将是相同的。
手册中有一节 描述如何使用或实现您自己的模板引擎。
You can extend Zend_View to use the same syntax as jQuery templating engine, this way both template would be the same.
There is a section in the manual describing how to use or implement your own template engine.