mdunisch
mdunisch

Reputation: 3697

EJS Template: Using forEach + include

I have many files in a Folder in want to include in a Template (EJS).

I try this:

 <% var test = ["foo.ejs"];
 _forEach(test, function(item){ %>
      <% include slides/item %>
  <% }); %>

I would use Nodejs to fill the Array by looking in a folder.

But i get the error:

 Error: ENOENT, no such file or directory 'app/views/slides/item.ejs'

It seems that ejs dont use "item" as a variable.

Upvotes: 1

Views: 1809

Answers (2)

Nurkhat Pazylov
Nurkhat Pazylov

Reputation: 11

Looks like this is now supported in EJS. It was introduced in v2.0.1: 2015-01-02. The new syntax looks like this

<%- include(yourVariable) %>

Upvotes: 1

RanP
RanP

Reputation: 802

There is an issue for that problem in github. https://github.com/visionmedia/ejs/issues/93

Upvotes: 0

Related Questions