<%
let myString = "this is a string %> with special characters";
let myotherString = "this is a string <% with special characters";
// Do something
%>
我需要在我的 JS 字符串 中使用这些特殊字符。但是 EJS 模板会返回错误:找不到匹配的“
编译 ejs 时无效或意外的标记我应该怎么做?
您可以简单地将两个字符串连接在一起:
let myString = "this is a string %" + "> with special characters";
或者使用模板文字来让它不那么难看:
let startTag = '<' + '%';
let myString = `this is a string ${startTag} with special characters`;
为了记录,their documentation 列出了更改开始/结束标签的选项,他们称之为分隔符,以防万一,例如<!
和 !>
。他们的文档还提到 <%%
应该打印 <%
但我个人不知道这是否适用于 <% code %>
块。