Question:
How to add EJS ForEach loop tag? Node.js

To add the EJS ForEach loop tag in Node.js, just use the EJS escaping syntax <%= in your code: 


Code:

<% data.forEach(function(row,index) { %>

    <a href="./post" class="article featured-article featured-article-<%= index+1 %>">

        <img src="/images/<%= row.image %>" alt="" class="article-image">

        <span class="article-category"><%= row.title %></span>


        <div class="article-data-container">


            <div class="article-data">

                <span><%= row.date %></span>

                <span class="article-data-spacer"></span>

                <span><%= row.date %></span>

            </div>


            <h3 class="title article-title"><%= row.title %></h3>


        </div>

    </a>

<% }); %>


Suggested blogs:

>Django Issue Solved: path searched will not match URL patterns

>Fix my form calling the wrong Django view error

>How is the value of the path column under the wagtailcore_page table populated?

>How to load static files using Nginx, Docker, and Django?

>How to tell Django "if anything in urlpatterns does not match the GET string?

>How can I browser to render links in streamed content in Django?

>Access the "model" attribute for a ListView in Django for template

>How to use a function to print S3 data to HTML using Django?


Ritu Singh

Ritu Singh

Submit
0 Answers