In EJS template engine, how do I "include" a footer? In EJS template engine, how do I "include" a footer? javascript javascript

In EJS template engine, how do I "include" a footer?


I know this question has already been marked as answered, but I believe what you were looking for is the 'partial' syntax. In EJS, you can include the content from one view template in another like so:

<html>  <head></head>  <body>    Blah blah blah    <%- partial('footer') %>      </body></html>


EJS makes it very simple to use includes. Here is how it is described in the EJS README:

Includes are relative to the template with the include statement, for example if you have "./views/users.ejs" and "./views/user/show.ejs" you would use <% include user/show %>. The included file(s) are literally included into the template, no IO is performed after compilation, thus local variables are available to these included templates.

<ul>  <% users.forEach(function(user){ %>    <% include user/show %>  <% }) %></ul>

So, in your case, if the footer resides in the same directory as the file you want to include it in, you would simply add <% include footer %> to your file.


You can include the ejs template by

<% include includes/header.ejs %>