Home > Blockchain >  ejs error saying could not find matching id
ejs error saying could not find matching id

Time:12-04

am new to mongoDB and eJS, am trying to display the content according to the collection id click, if i console the id am getting the id but if am pushing the content to the detials am getting an error: Error: Could not find matching close tag for "<%=". please what am I doing wrong here?

Here's my code

//my app.js file

app.get("/blogs/:id", (req, res) => {
    const id = req.params.id

    console.log(id)

    Blog.findById(id)
    .then((result) => {
        res.render('details', {title: "details page", blog: result})
    })
        .catch(err => console.log(err))
})

my details file

<!DOCTYPE html>
<html lang="en">
    <%- include("./partial/head.ejs") -%>
<body>
  <div >
    <%- include("./partial/nav.ejs") -%>
    
    
    <div >
        <h1><%=blog.title></h1>
        <p><%=blog.body></p>
    </div>

    <%- include("./partial/footer.ejs") -%>
    </div>
</body>
</html>

CodePudding user response:

error message says that EJS is unable to find a matching closing tag for the <%= tag that is used to output the value of the blog.title variable.

you have to add a closing tag for the <%= tag. In EJS, the closing tag for this tag is %>. So, you need to add this closing tag after the blog.title variable in your template.

<h1><%=blog.title%></h1>

Similarly, you need to add a closing tag for the <%= tag that is used to output the value of the blog.body variable, like;

<p><%=blog.body%></p>
  • Related