How to include HTML code in a view?

I use express.js and EJS as a template engine. I don’t understand how to use partial ones, I saw with examples, but the author used the mechanism of the JADE-template, so I don’t know how to apply it with EJS.

I have a simple view named: test.ejs and another .ejs file called part1.ejs

I need to show part1.ejs inside test.ejs.

I tried putting <% partial('part1', {}) %> (in test.ejs), but nothing happens, it does not include this file.

Can someone give me an example?

Thanks!

+7
source share
2 answers

The correct code in your situation:

 <%- partial('part1') %> 

If you want to enable unescaped HTML, use <%- , and if you want to avoid HTML (involuntarily, although when you enable partial) you can use <%= .

Resources

Node.js - EJS - including partial
http://groups.google.com/group/express-js/browse_thread/thread/62d02af36c83b1cf

+11
source

Its an old thread, but here is how you do it in the new version of EJS.

 <% include part1 %> 

this part1.ejs contains the html that you want to include.

+4
source

All Articles