0

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?

shennan
  • 10,798
  • 5
  • 44
  • 79
  • _"would a regular expression be out-of-the-question?"_ Yes, it would. – Cerbrus Jul 08 '14 at 11:30
  • [Yes](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags), regular expressions are out of the question. – RevanProdigalKnight Jul 08 '14 at 11:36
  • Have you tried using an external script? – RevanProdigalKnight Jul 08 '14 at 11:37
  • @RevanProdigalKnight unfortunately my use-case is one that requires the data to be injected directly into the HTML. – shennan Jul 08 '14 at 11:40
  • @Cerbrus you're conveniently ignoring the prepended "for the simple injection of a stringified object into a certain – shennan Jul 08 '14 at 12:28
  • if the <% %> are what bothers you, afaik you can change these to [% %]: https://code.google.com/p/embeddedjavascript/wiki/Templates#Example Alternatively you can look at (for example) swig (https://paularmstrong.github.io/swig/). – masch Jul 08 '14 at 12:34
  • @masch this still breaks the original template file – shennan Jul 15 '14 at 11:27

1 Answers1

-1

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>
Sky
  • 231
  • 1
  • 2
  • 5