如何将Underscore.js模板与EJS结合使用? [英] How can I use Underscore.js templates in conjunction with EJS?
本文介绍了如何将Underscore.js模板与EJS结合使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它们都使用相同的语法来插入变量。例如,如果我想要以下
They both use the same syntax for inserting variables. For example if I want the following
<%= username %>
在我的下划线中,我的主要EJS因为试图替换用户名而中断,并且没有这样的变量存在于主页。
In my Underscore, my main EJS breaks because it tries to replace username and no such variable exists in the main page.
推荐答案
我认为方括号默认在EJS中起作用:
I think square brackets will work in EJS by default:
[%= username %]
如果你需要得到更好的信息,EJS github页面描述了如何创建自定义标签:
And if you need to get fancier, the EJS github page describes how to create custom tags:
var ejs = require('ejs');
ejs.open = '{{';
ejs.close = '}}';
- 我认为第二个发烧友部分可能是特定于服务器的 - 附加申请
https: //github.com/visionmedia/ejs
使用客户端GitHub示例,渲染时需要执行以下语法:
Using the client side GitHub example, you'd need to do syntax like this when you render:
var html = require('ejs').render(users, { open: "^%", close: "%^" });
选项是 render()$ c $的第二个参数c>。
这篇关于如何将Underscore.js模板与EJS结合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文