Reputation: 324
I get a list of ID's from API, that needs to be added to a URL inside an EJS template, so I can fetch the correct items.
Example URL: http://url.com/get/:id
Example ID's: 526 876 929
needed result inside EJS template:
<li> http://url.com/get/526 </li>
<li> http://url.com/get/876 </li>
<li> http://url.com/get/929 </li>
I got the list of ID's as needed, but I can't figure out why my forEach loop won't return the URL+ID.
This is console.log of message:
[ 526, 876, 929 ]
This is the EJS file:
<% var itemurl = "http://url.com/get/" %>
<% message.forEach(itemView) => { %>
<%= item url + itemView %>
<% }); %>
I keep getting syntax errors and obviously I'm missing something.
Upvotes: 0
Views: 153
Reputation: 329
<% var message = [112,232,533] %>
<% var itemurl = "http://url.com/get/" %>
<% message.forEach((itemView) => { %>
<%= itemurl + itemView %>
<% }); %>
you were missing an open parenthesis and had a space in itemurl
Upvotes: 1