Skip to content

include not a function error #525

Open
@richlewis14

Description

@richlewis14

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

mde commented on Jun 14, 2020

@mde
Owner

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

woodscreative commented on Jul 26, 2020

@woodscreative

Using EJS 3.1.3 with Express 4.17.1 and cannot get includes to work either include not a function without async.

eyupahmetyilmaz

eyupahmetyilmaz commented on Nov 25, 2021

@eyupahmetyilmaz
const readAndCompileFile = async filePath => {
  const file = await readFile(filePath);
  return ejs.compile(file, { r_client: true });
};

If you using "include" in .ejs file, don't use client

ahmedseada

ahmedseada commented on Dec 9, 2021

@ahmedseada

@eyupahmetyilmaz spent 3 hours looking for the error beacuse i was using 'client' .
thanks alot

LeoSko

LeoSko commented on Jun 12, 2022

@LeoSko

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

UdayaBandara commented on Jul 26, 2022

@UdayaBandara
const readAndCompileFile = async filePath => {
  const file = await readFile(filePath);
  return ejs.compile(file, { r_client: true });
};

If you using "include" in .ejs file, don't use client

thank you very much. spend so many hours because this word "client"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mde@richlewis14@LeoSko@woodscreative@ahmedseada

        Issue actions

          include not a function error · Issue #525 · mde/ejs