简体   繁体   English

像EJS这样的节点模板引擎不会破坏HTML模板吗?

[英]Node template engine, like EJS, that doesn't break the HTML template?

Wondering if there is a templating engine like EJS for NodeJS that doesn't break the original template HTML through its use of parenthesis. 想知道是否有像EJS for NodeJS这样的模板引擎不会通过使用括号破坏原始模板HTML。

In EJS, for example, one might use the following to insert specific data into the HTML template: 例如,在EJS中,可以使用以下内容将特定数据插入HTML模板:

<script>
    window.$data = <%- JSON.stringify(data, null, 4) %>;
</script>

Note that the <%- %> parenthesis breaks the source HTML file, rendering it useless for quick-fire testing in situations when your want to temporarily drop the use of the EJS parser. 请注意, <%- %>括号会中断源HTML文件,在您要暂时放弃使用EJS解析器的情况下,它无法用于快速射击测试。

Ignoring disputes of usefulness for a moment, are there any good data-injection libraries for Node which don't break the template? 暂时忽略有用性争议,是否有一些不破坏模板的Node良好的数据注入库? Or, dare I say, for the simple injection of a stringified object into a certain <script> element, would a regular expression be out-of-the-question? 或者,我敢说,对于将字符串化的对象简单地注入到特定的<script>元素中,正则表达式会毫无疑问吗?

As you know, EJS would break HTML with it's '<% >' , and the syntax of it looks much like ASP. 如您所知,EJS会使用'<%>'破坏HTML,其语法看起来很像ASP。

If you want a new template which not break HTML, and has a nice coding work flow, you can try this: 如果您想要一个不破坏HTML且具有良好编码工作流程的新模板,则可以尝试以下操作:
Github: https://github.com/eshengsky/saker GitHub: https : //github.com/eshengsky/saker

It's my personal open source project named Saker, it enables a really compact and expressive syntax which is clean, fast and fun to type. 这是我个人的名为Saker的开源项目,它启用了一种非常紧凑和表达力强的语法,该语法简洁,快速且易于输入。

Here's the preview: 这是预览:

<span>@name</span>
<a href="/detail/@id">@title</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM