合并客户端/服务器端模板引擎

时间:2022-05-12 16:25:22

I'm about to start a new project using node, backbone, underscore, and express among other things. On the views side I am using jade. I know I am going to have tons of ajax like interactions so I was going to use handlebars; however, I feel that there would be a significant amount of code duplication from my jade templates.

我即将开始使用节点,主干,下划线和表达等新项目。在观点方面,我使用的是玉。我知道我会有很多类似于交互的ajax,所以我打算使用把手;但是,我觉得我的jade模板会有大量的代码重复。

  1. Is there a way to render the jade templates and fill in data straight from client side? How can I route requests directly to the views without filling in the data?
  2. 有没有办法渲染玉石模板并直接从客户端填写数据?如何在不填写数据的情况下将请求直接路由到视图?
  3. If I can't do the above it seems that I actually have a few templating engines I could use, underscore, jquery, handlebars... Is it not a waste to have all of those templating engines laying around? Should I just use underscore or jquery and not even worry about handlebars any more? Is there a preferred engine?
  4. 如果我不能做到这一点,似乎我实际上有一些我可以使用的模板引擎,下划线,jquery,把手......让所有这些模板引擎摆放不是浪费吗?我应该只使用下划线还是jquery,甚至不再担心把手?有首选发动机吗?
  5. Is there some hybrid method where I can fill in data similarly to handlebars into my jade templates?
  6. 是否有一些混合方法,我可以将类似于把手的数据填入我的玉石模板中?

1 个解决方案

#1


3  

Express isn't doing any magic with jade template rendering. Simply have a look at the public api and you know how to render jade views on the client side. For routing requests on the client side you can use page.js from the express author. A little bit of work and magic and you have routes working with the exact same code on the server and client side and both are rendering to jade.

Express没有使用玉模板渲染做任何魔术。只需查看公共API,您就知道如何在客户端呈现玉视图。对于客户端上的路由请求,您可以使用来自明文作者的page.js。一点点的工作和魔力,你有在服务器和客户端使用完全相同的代码的路由,并且两者都呈现为玉。

#1


3  

Express isn't doing any magic with jade template rendering. Simply have a look at the public api and you know how to render jade views on the client side. For routing requests on the client side you can use page.js from the express author. A little bit of work and magic and you have routes working with the exact same code on the server and client side and both are rendering to jade.

Express没有使用玉模板渲染做任何魔术。只需查看公共API,您就知道如何在客户端呈现玉视图。对于客户端上的路由请求,您可以使用来自明文作者的page.js。一点点的工作和魔力,你有在服务器和客户端使用完全相同的代码的路由,并且两者都呈现为玉。