[英]How to pass html tags in a string with node.js, express and ejs
[英]How to use EJS tags in a JS string
<%
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`;
作为记录,他们的文档列出了更改开始/结束标签的选项,他们称之为分隔符,以防您喜欢例如<!
和!>
。 他们的文档还提到<%%
应该打印<%
但我个人不知道这是否适用于<% code %>
块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.