use of partials with ejs

666 views
Skip to first unread message

MK

unread,
May 21, 2011, 7:32:31 AM5/21/11
to Express
I have a template that is a whole page. I have another template that
is a fragment of a page, ie, a partial.
I would like to include the partial in the page, so in the "parent"
template I have:

<%=partial('file', {})=%>

In my experience, this is a pretty basic, more or less definitive, use
of "partials" -- rather than having to repeat a fragment in several
different templates, I just include one within the other.

But absurdly enough (IMO), with express html tags in this html partial
are then parsed into &lt; and &gt;. In other words, express is
treating this exactly the same as if I had replaced the partial() call
in the parent with a variable named "here" and done this:

var html = fs.readFileSync('file');
res.render('parent', {
here: html,
}

Is there a way I can turn off the tag parsing? Or something?

Joshua Cohen

unread,
May 21, 2011, 6:24:41 PM5/21/11
to expre...@googlegroups.com
I believe in ejs you have to use <%- %> to emit unescaped html, <%= %> will always escape. I've not used it, so I'm just going based on what I've read elsewhere (like this old thread from this list for example: http://groups.google.com/group/express-js/browse_thread/thread/e88326f93c0a802c).


--
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.


Laurie Harper

unread,
May 22, 2011, 12:50:00 AM5/22/11
to expre...@googlegroups.com
Exactly; partial() will return HTML; the template engine directives determine what to do with it.

Reply all
Reply to author
Forward
0 new messages