Open
Description
Hi,
I am positive that the above error is caused by my implementation or use of ejs, but I have a scenario where I am trying to render a partial within a partial, this particular section of the view gets rendered after an Ajax call (I'm trying to split my views into smaller components)
I have a view file views/home.ejs
and within that I have <%- include('test-component') %>
The error I get is include is not a function
When sending the rendered html back to the client it is compiled through
const readAndCompileFile = async filePath => {
const file = await readFile(filePath);
return ejs.compile(file, { client: true });
};
const sendHtml = async (data, res) => {
const template = await readAndCompileFile(TEMPLATE_FILE_PATH);
const html = template({ ...data, Utilities, moment });
return res.send({ html });
};
I hope this is enough information but if anything further is needed then please advise
I am on the latest version of ejs, 3.1.3
Thank You
Activity
mde commentedon Jun 14, 2020
I would need to see more code to understand what you're trying to do, and what's not working. From your initial description, it's possible that the error stems from your asynchronous rendering steps, but this is just a guess.
woodscreative commentedon Jul 26, 2020
Using EJS 3.1.3 with Express 4.17.1 and cannot get includes to work either
include not a function
without async.eyupahmetyilmaz commentedon Nov 25, 2021
If you using "include" in .ejs file, don't use client
ahmedseada commentedon Dec 9, 2021
@eyupahmetyilmaz spent 3 hours looking for the error beacuse i was using 'client' .
thanks alot
LeoSko commentedon Jun 12, 2022
My mistake here was that I didn't provide a proper callback for rendering of included template, but only on top-level template rendering, which resulted in exactly that error. A working (kinda minimal) example: https://jsfiddle.net/cjw57p6n/41/
UdayaBandara commentedon Jul 26, 2022
thank you very much. spend so many hours because this word "client"
remove client:true in ejs options as it was leading to errors while t…