Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - EJS - including a partial

Tags:

node.js

ejs

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.

like image 692
jeffreyveon Avatar asked Mar 23 '11 11:03

jeffreyveon


People also ask

What is partial in EJS?

Partials come in handy when you want to reuse the same HTML across multiple views. Think of partials as functions, they make large websites easier to maintain as you don't have to go and change a piece of text in every page it appears in.

Is EJS better than handlebars?

EJS is way faster than Jade and handlebars. EJS has a really smart error handling mechanism built right into it. It points out to you, the line numbers on which an error has occurred so that you don't end up looking through the whole template file wasting your time in searching for bugs.


1 Answers

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 v1 includes
EJS v2 includes

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

like image 151
Philipp Kyeck Avatar answered Sep 18 '22 09:09

Philipp Kyeck