Home > front end >  Passing data syntex missing
Passing data syntex missing

Time:12-01

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

<!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 >
            <h2><%= blog.title %></h2>
            <p><%= blog.content %></p>
        </div>
        <% } else {%>
            <h2> There's no blog post</h2>
        <% })%>  
    <% }%> 

</body>
</html>

CodePudding user response:

Replace } else

To

})}

And remove last })

  • Related