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.
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.
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.
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') %>
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With