Basically, I can't figure out how to use an EJS "variable" (don't know the real name for it. In my case it's <%=postContent[i]%>
) within an EJS if statement as shown below.
<% for (i = 0; i <= 10; i++) { %>
<% if (<%-postContent[i]%>.includes('gyfcat')) { %>
<div>PLACEHOLDER</div>
<% } else { %>
<img src="<%=postContent[i]%>" class="redditImages">
<% } %>
<% } %>
I basically want it so when the string "gyfcat"
is in the postContent
string (it's a URL), the first block of code runs, else, runs the <img>
code.
The error I'm getting is Error: Could not find matching close tag for "<%".
只需删除postContent[i]
周围的<%=
和%>
postContent[i]
解决我的问题。
<div>
<% if(typeof datas !='undefined') { %>
<% datas.forEach(function(data) { %>
<div> Id:<%= data.id %></div>
<div> Title:<%= data.title %></div>
<div> Body:<%= data.body%></d>
<% }); %>
<% } %>
</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.