Thursday, January 20, 2011

EJS default escaping

In EJS (Embedded JavaScript) escaping is a default behaviour.

// escape by default
<%= VARIABLE_NAME %>

This can easily mess up a couple of things (including JSON, HTML rendering), luckily you can turn it off by using

// render out string
<%- VARIABLE_NAME %>

8 comments:

  1. Ooooh thanks man, I love you. EJS has such poor docs...

    ReplyDelete
  2. Many thanks. I could easily have spent another hour trying to figure out the escaping problem. I was trying to output some quick and dirty XML, and the escaping was driving me crazy!

    ReplyDelete
  3. This has left me scratching my head for over a day! Thanks for the great explanation.

    ReplyDelete
  4. "I very much enjoyed this article.Nice article thanks for given this information. i hope it useful to many pepole.php jobs in hyderabad.
    "

    ReplyDelete