7

I'm using express.js and EJS as template engine. I don't understand how to use partials, I have seen at the examples but the author used JADE template engine, so I don't know how to apply it with EJS.

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

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

I tried putting <% partial('part1', {}) %> (into test.ejs) but nothing happen, It does not include that file.

Could someone give me an example?

Thank you!

Dail
  • 4,622
  • 16
  • 74
  • 109

2 Answers2

11

The correct code in your situation would be:

<%- partial('part1') %>

If you want to include unescaped HTML use <%- and if you want to escape HTML (unlinkely though when including a partial) you can use <%=.

Resources:

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

Community
  • 1
  • 1
alessioalex
  • 62,577
  • 16
  • 155
  • 122
4

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

<% include part1 %>

given part1.ejs contains the html you wish to include.