SyntaxError: missing ) after argument list while compiling ejs

SyntaxError: missing ) after argument list while compiling ejs

header.ejs 文件包含:

<html>
    <head>
        <title>
            Random Ejs testing
        </title>
        <link rel="stylesheet" href="/app.css">
    </head>
    <body>

并且页脚文件包含:


           <p> Made By Shashank Singh </p>
    </body>
</html>

我试图将这些模板包含在我的 mammal.ejs 文件中,但出现错误: Mammal.ejs:

<%- include partials/header%>

<h1>Hello</h1>

<%- include partials/footer%>

您的代码有两个问题。第一个是您必须使用方括号和引号作为文件名。 mammal.ejs 的修复版本应如下所示:

<%- include('partials/header')%>

<h1>Hello</h1>

<%- include('partials/footer')%>

可能存在的另一个问题是您包含的文件还应具有 .ejb 扩展名。因此,请确保您已将文件命名为 partials/header.ejbpartials/footer.ejb.

希望这对您有所帮助。

仅供参考,我尝试使用以下代码进行渲染:

const ejs = require("ejs");

ejs.renderFile("mammal.ejs", null, {}, function(err, str){
    console.log("ERR", err);
    console.log("RESULT", str);
});

你应该尝试遵循 suggestion.It 对我有用并且应该对你有用。

` <%- include('./partials/header.ejs');%>

<%- include('./partials/footer.ejs');%> `