Node.js - EJS - including a partial

jeffreyveon picture jeffreyveon · Mar 23, 2011 · Viewed 119.9k times · Source

I am trying to use Embedded Javascript renderer for node: https://github.com/visionmedia/ejs

I would like to know how I can include another view file (partial) inside a .ejs view file.

Answer

pkyeck picture pkyeck · Jul 7, 2011

With Express 3.0:

<%- include myview.ejs %>

the path is relative from the caller who includes the file, not from the views directory set with app.set("views", "path/to/views").

EJS includes

(Update: the newest syntax for ejs v3.0.1 is <%- include('myview.ejs') %>)