Embedded JavaScript (ejs) Tag Family: <%, <=, <%- and -%>

The following should be true up to ejs 0.8.3:

<% %> or [% %] tags are used to execute javascript code. Something like

<% log = “hi” %>

will set hi equal to the global javascript variable ‘log’.

<%= %> or [%= %] is used to execute code, and then print the tostring of the result to the screen. Thus, something like

<%= log %>

will print out ‘hi’ to the screen. Note that HTML is escaped when using this tag. Thus, <%= <img src=”blahblah”> %> will print literally ‘<img src=”blahblah”>.

<%- %> is used to allow ‘unescaped buffering’, which essentially means that HTML is NOT escaped, and thus you can do something like <img src=”blah”> and have an image actually render to the page.

<% -%> tag slurps a newline following the expression. Thus, something like

var x = ‘inbetween’;

str = ‘me <%= x %> \nhere’;


should return the result ‘me inbetween here’ (newline after is slurped).

The last tag was added to ejs in this github chain for those interested:



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s