I am getting the error Unexpected token ) while compiling ejs
when doing translation using i18next.
I have implemented the translation using i18next, below is the following code, getting the following error when using map function
en.json
{
"title": "List of Countries",
"list":[{
"name": "Singapore",
"code": "SG"
},{
"name": "Thailand",
"code": "TH"
}]
}
index.ejs
<h4><%=t('title')%></h4> //outputs correctly
<ul>
<%=t('list').map(e=>{%>
<li><%=e.name%></li>
<%})%>
</ul>
Your ejs scripts are incorrect when iterating over the array, you need to remove the assign character when iterating and use the object "e" instead of "li" as follows:
<ul>
<%_ t('list').map(e=>{-%>
<li><%=e.name%></li>
<%_ }) -%>
</ul>
Use:
"<%_" to remove previous whitespaces when rendering the ejs
"-%>" to remove the line
See official ejs docs for more details
Just remove the assign character and you are ok.
<ul>
<% t.list.map(e => {%>
<li><%=e.name%></li>
<%})%>
</ul>
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.