ejs templates being escaped on render call

1,301 views
Skip to first unread message

Brian LeRoux

unread,
Aug 2, 2010, 9:30:23 PM8/2/10
to expre...@googlegroups.com
Hey guys, any ideas what I'm doing wrong?

// app.js
var app = require('express').createServer();

app.get('/', function(req, res){
res.render('index.ejs');
});

app.listen(3000);

// views/layout.ejs
<html>
<body><%= body %></body>
</html>

// views/index.ejs
<p>hello world</p>

// Expected on GET "/"
<html>
<body><p>hello world</p></body>
</html>

// Actual on GET "/"
<html>
<body>&lt;p&gt;hello world from index&lt;/p&gt;</body>
</html>

Brian LeRoux

unread,
Aug 2, 2010, 9:34:06 PM8/2/10
to Express
OH OF COURSE I FIND THE ANSWER AFTER HITTING SEND!

// escape by default
<%= %>

// render out string
<%- %>

(Not entirely what I would expect but thats certainly no measure of
normalcy. Btw, anyone got MustacheJS compat/shim for Express yet?)

vision media [ Tj Holowaychuk ]

unread,
Aug 2, 2010, 10:58:22 PM8/2/10
to expre...@googlegroups.com
Sorry, that seems to be confusing a lot of people lol I just prefer to escape by default
since some people are not careful about that :) An option to toggle might be nice.

I dont think so, I had the request for an api to register non-compliant engines, so
I hopefully will have time for that soonish. 

--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.




--
Tj Holowaychuk
Vision Media
President & Creative Lead

Brian LeRoux

unread,
Aug 2, 2010, 11:23:30 PM8/2/10
to expre...@googlegroups.com
Cool thx tj --- I like the default now that I'm aware of it. ;)

As to mustache --- All I'd need to do is create a render method and
register it to an engine called mjs? (then require('mjs') just
requires mustachejs)

Sounds about right?

vision media [ Tj Holowaychuk ]

unread,
Aug 3, 2010, 10:24:58 AM8/3/10
to expre...@googlegroups.com
Yup currently the signature is:

   render(templateStr, options) -> String

Ideally changed to this for future proofing:

   render(templateStr, options, callback) -> callback(err, String)

The change should not be to involved, however need to rewrite jade tests to be much uglier :D and implement view partial placeholders.
Reply all
Reply to author
Forward
0 new messages