0

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>
2
  • What is this <%= task %>. Commented Jan 11, 2019 at 21:02
  • it's supposed to be my task item render, so it's supposed to be javascript Commented Jan 11, 2019 at 21:05

2 Answers 2

1

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 !

Sign up to request clarification or add additional context in comments.

1 Comment

I just ask about it because it is shown that the task is not defined.
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.