I have a syntax error when I trie to render this part of my template with EJS (on a node server).
The error is in this code part, I'm sure I have a pb with tags "<%" but I don't understand where.
<p>
<% tasks.map(task => ( %>
<%= task %>
<% )) %>
</p>
Here is my full template :
<h1>My todolist</h1>
<p><% tasks.map(task => ( %>
<%= task %>
<% )) %>
</p>
<form method="post" action="/task">
<input type="text" placeholder="Add task" name="newTask" />
<button type="submit">Add</button>
</form>
Thanks for your answer. I finally solved the problem. "task" wasn't the trouble.
It seems I can't use ES6 syntax to quickly return something
I changed this :
<p><% tasks.map(task => ( %>
<%= task %>
<% )) %>
</p> %>
with this :
<p><% tasks.map(task => { %>
<%= task %>
<% }) %>
</p>
And now it works perfectly !
Try this:
<h1>My todolist</h1>
<p>
<% tasks.map(task => {
%> <%=task %><%});%>
</p>
<form method="post" action="/task">
<input type="text" placeholder="Add task" name="newTask" />
<button type="submit">Add</button>
</form>
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.