How to use ejs "include" in templates

See original GitHub issue

Hello,

I am trying to use this project with ejs. I have a lot of pain to understand how the rendering system works and how the template files coulds / should be structured and chained.

In my case, I can’t maket it work without having one folder by template, containing a html.ejs file. Is it normal and mandatory or can we specify a filePath ?

Here is my app structure :

app.js
templates
   - emails
     - administrators
       - bottom-wrapper
         - html.ejs
       - notification-note
         - html.ejs
       - top-wrapper
         - html.ejs

I want to render the notification-note template, which contains :

<%- include('../top-wrapper') %>

TEST

<%- include('../bottom-wrapper') %>

Here is the way I’m calling it :

const email = new Email({
     message: message,
     transport: EmailService.transport(),
     views: {
          options: {
              extension: 'ejs'
          },
          root: path.join('templates', 'emails')
     }
 });
return email.send({
      template: "administrators/notification-note",
      locals: locals
})

I run into this error :

Could not find the include file "../top-wrapper"

I can’t figure out how to make this work. Did someone already do this ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

12reactions
c831216commented, Mar 22, 2020

<%- include(‘file path’); -%>

It worked for me when I added the ‘-’ at the end

2reactions
johnfradescommented, Dec 11, 2018

Hi, i have the same situation and here’s how i solve it

   app.js
   - emails
     - new-question
       - html.ejs
       - subject.ejs
     - views
       - header.ejs
       - footer.ejs

and on the html.ejs of new-question

<% include ../views/header.ejs %>

CONTENT

<% include ../views/footer.ejs %>
Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use EJS to Template Your Node Application
Use <% - include( 'RELATIVE/PATH/TO/FILE' ) %> to embed an EJS partial in another file. The hyphen <%- instead of just <% to...
Read more >
EJS -- Embedded JavaScript templates
Includes are relative to the template with the include call. (This requires the 'filename' option.) For example if you have "./views/users.ejs" and "./views/ ......
Read more >
In EJS template engine, how do I "include" a footer?
include is a function Includes are relative to the template with the include call. (This requires the 'filename' option.) For example if you ......
Read more >
How to use EJS to template your Node.js application
Template your Node.js apps with EJS, a simple and powerful templating ... Create a new folder where you want to put the project...
Read more >
Using EJS Template Engine With Express.js
js file, open your editor, and write down the following code: 1 2 3 4 5 6 7 8 9 10 11 12...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found