[英]How to escape ejs tags inside an ejs template string?
How can we escape the ejs tags itself inside a template? 我们如何在模板中逃避ejs标签?
In sails I would like to put the following code in the layout.ejs 在sails中,我想将以下代码放在layout.ejs中
<!--STYLES-->
<% if (typeof head_css != 'undefined') { %>
<%= head_css %>
<% } else { %>
<% if (typeof head_css_before != 'undefined') { %>
<%= head_css_before %>
<% } %>
<link rel="stylesheet" href="/styles/importer.css">
<% if (typeof head_css_after != 'undefined') { %>
<%= head_css_after %>
<% } %>
<% } %>
<!--STYLES END-->
but by default, all the things inside the <!--STYLES-->
and <!--STYLES END-->
are replaced by this template: 但默认情况下,
<!--STYLES-->
和<!--STYLES END-->
都被此模板替换:
<link rel="stylesheet" href="%s">
as in the sails-linker.js
. 就像在
sails-linker.js
。
So instead of the template <link rel="stylesheet" href="%s">
I would like put something some more complex things, than when rendered the result becomes: 所以不是模板
<link rel="stylesheet" href="%s">
我想把一些更复杂的东西放在比渲染时结果变成:
<!--STYLES-->
<% if (typeof head_css != 'undefined') { %>
<%= head_css %>
<% } else { %>
<% if (typeof head_css_before != 'undefined') { %>
<%= head_css_before %>
<% } %>
<link rel="stylesheet" href="/styles/importer.css">
<% if (typeof head_css_after != 'undefined') { %>
<%= head_css_after %>
<% } %>
<% } %>
<!--STYLES END-->
But the problem is when I try something like 但问题是当我尝试类似的东西时
<%= special_code_here %><link rel="stylesheet" href="%s">
this is automatically rendered. 这是自动渲染的。 I need to escape the
<%
inside a ejs template. 我需要逃避ejs模板中的
<%
。
How can we do this? 我们应该怎么做?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.