how to include a template with parameters in EJS?

ejs
Orkun Ozen picture Orkun Ozen · Mar 22, 2015 · Viewed 42.2k times · Source

As a real beginner in EJS, I have two charts in my html page, so I want to use my partial twice:

<% include partials/spider-chart.ejs %>

But I need to pass some parameters inside the ejs to differentiate between graphs.

What is the best way?

Answer

Zubair Alam picture Zubair Alam · Nov 17, 2016

@Naeem Shaikh solution works. Though include also gives you more intuitive way of including a partial template and also passing context variables to that as found in documention section of ejs.

<ul>
  <% users.forEach(function(user){ %>
      <%- include('user/show', {user: user}); %>
  <% }); %>
</ul>