Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Passing data syntex missing

please am new to nodeJS and EJS. am trying to map some data am sending from my app file to my EJS file but am getting an error: SyntaxError: missing ) after argument list, everything is working except the blogs data, what am doing wrong

Here’s my code
//app.js

const express = require("express")
const app = express()

app.listen(3000)

app.set("view engine", "ejs");
app.set('views', __dirname + '/views');

app.get("/blogs", (req, res) => {
    const blogs = [{title: "first blog", content:"this a my first blog post"},
        { title: "first blog", content: "this a my second blog post" }]
    res.render("blogs", { title: "home", blogs})

//blog.ejs

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<!DOCTYPE html>
<html lang="en">
    <%- include("./partial/head.ejs") %>
<body>

    <%- include("./partial/nav.ejs") %>
    
   <h3>All Blogs</h3>
    
     <div>
    <% if (blogs.length > 0){ %>
        <% blogs.forEach(blog => {%>
        <div class="contents">
            <h2><%= blog.title %></h2>
            <p><%= blog.content %></p>
        </div>
        <% } else {%>
            <h2> There's no blog post</h2>
        <% })%>  
    <% }%> 

</body>
</html>

>Solution :

Replace
} else

To

})}

And remove last })

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading