Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EJS: <%= versus <%-

Tags:

I'm using EJS with a Node.js web server I'm building. I see many EJS examples that sometimes use <%= when outputting HTML or strings, while other examples (sometimes within the same template) use <%-.

I tried to reference the EJS docs and getting started guide, but both gave no info about the <%- notation. Also, my Google search attempts yielded nothing useful. Thanks!

like image 372
Matt Huggins Avatar asked Jun 13 '12 23:06

Matt Huggins


People also ask

What is <%- in EJS?

With <%= you if would render some variables that holds a string that holds HTML code, it would not render that HTML code but render it as text to avoid cross-site scripting attacks. With a minus ( <%- ) you can avoid this, and really render the HTML code.

What does <% mean in EJS?

The following is from ejs docs (tag section): <% 'Scriptlet' tag, for control-flow, no output. <%= Outputs the value into the template (HTML escaped) <%- Outputs the unescaped value into the template.

Which is better EJS or Pug?

According to the StackShare community, Pug has a broader approval, being mentioned in 230 company stacks & 608 developers stacks; compared to EJS, which is listed in 9 company stacks and 13 developer stacks.


1 Answers

The version of EJS you're likely using in Node is not the same as the version you see on Google code; in the Node version, <%= escapes the HTML going into the buffer, while <%- does not. source

like image 151
Michelle Tilley Avatar answered Oct 01 '22 19:10

Michelle Tilley