Issue while using ejs syntax

Viewed 26

This is my ejs file(_post.ejs):

<link rel="stylesheet" href="/css/home.css">

<div id="home-container">
    <% if(locals.user){%>
    <section id="feed-posts">
        <h4>Posts</h4>
        <form action="/posts/create" method="post" id="new-post-form">
            <textarea name="content" cols="30" rows="3" placeholder="Type here..." required></textarea>
            <input type="submit" value="Post">
        </form>
    </section>
    <%}%>
        
        <section id="posts-wall" >
            <ul>
                <% for(post of Posts){ %>
                <%- include('_post') -%>
                <hr>
                <% } %>
            </ul>
        </section>
        
        <section id="user-friends">
            <h4>Friends</h4>
            <% for(u of all_users){%>
                <p>
                    <a href="/users/profile/<%= u.id %>" style="color:blue;"><%= u.username %></a>
                </p>

            <%}%>
        </section>
</div>
<script src="/js/home_posts.js"></script>

Error :

Error: /Users/nishantbhatia/Desktop/nodews/codial/views/home.ejs:17
    15|             <ul>
    16|                 <% for(post of Posts){ %>
 >> 17|                 <%- include('_post') -%>
    18|                 <hr>
    19|                 <% } %>
    20|             </ul>

I have included the closing tags as well. Really not sure abt the error. Any help would be appreciated.I tried to read the documentation still no clue.

1 Answers

The syntax should be ,remove - from closing tag. See the docs

<section id="posts-wall" >
            <ul>
                <% for(post of Posts){ %>
                <%- include('_post') %>
                <hr>
                <% } %>
            </ul>
        </section>
Related