Include return of a foreach within the background-image url

Asked

Viewed 29 times

-1

Speak guys, I need to include the return of a foreach within the url of a background-image, please can help me:

<!-- Slide 1 -->
<% DTSection0.forEach(function(row){ %>
       <div class="item" style="background-image: url(assets/img/site/slider/<%= row.imagem %>)"></div>
<% }); %>

See when placing <%= Row.image %> inside the error url and the image does not click on the page.

I am using Node.JS and my pages are in . ejs.

Print aqui

  • You can show how the ejs-generated HTML is?

  • So you’re not returning anything... it’s empty. made a console.log and the query as well as the foreach is ok, the problem is in that part right there to include the <%= Row.image %> inside the url

  • But appears the <div class="item"?

  • you are right Sergio, only one image should be active item, the others have to be only item, I will put here and already put the answer, thanks.

1 answer

0

Solution:

<!-- Slide 1 -->
<% DTSection0.forEach(function(row){ 
    if(row.active == 1){ %>
      <div class="item active" style="background-image: url(assets/img/site/slider/<%= row.imagem %>)"></div>
    <% } else{ %>
      <div class="item" style="background-image: url(assets/img/site/slider/<%= row.imagem %>)"></div>
    <% }; %>
<% }); %>

The problem was in class="active item", only 1 image has to be active, the rest must be only class="item".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.