如何结合 jQuery tmpl 和 Zend Views(避免代码重复)

发布于 2024-12-22 10:36:23 字数 681 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨洒年华 2024-12-29 10:36:23

您可以扩展 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文