简体   繁体   中英

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.

In EJS, for example, one might use the following to insert specific data into the HTML template:

<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.

Ignoring disputes of usefulness for a moment, are there any good data-injection libraries for Node which don't break the template? 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?

As you know, EJS would break HTML with it's '<% >' , and the syntax of it looks much like ASP.

If you want a new template which not break HTML, and has a nice coding work flow, you can try this:
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.

Here's the preview:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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