admin管理员组文章数量:1429064
How can we escape the ejs tags itself inside a template?
In sails I would like to put the following code in the 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:
<link rel="stylesheet" href="%s">
as in the sails-linker.js
.
So instead of the template <link rel="stylesheet" href="%s">
I would like put something some more plex things, than when rendered the result bees:
<!--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.
How can we do this?
How can we escape the ejs tags itself inside a template?
In sails I would like to put the following code in the 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:
<link rel="stylesheet" href="%s">
as in the sails-linker.js
.
So instead of the template <link rel="stylesheet" href="%s">
I would like put something some more plex things, than when rendered the result bees:
<!--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.
How can we do this?
Share Improve this question asked Feb 3, 2017 at 22:28 GarouDanGarouDan 3,83310 gold badges50 silver badges78 bronze badges 2-
Have you tried the HTML entities for
<
and>
, which are<
and>
? – Scott Marcus Commented Feb 3, 2017 at 22:38 -
@ScottMarcus Yes, I tried. The problem with this is was rendered as html entities in the layout.ejs file and there I should have the non-escaped
<%
. So in the browser appear the code I would like to have but as a plain text. – GarouDan Commented Feb 3, 2017 at 22:51
1 Answer
Reset to default 6<%%
escapes the EJS tags, and will give you <%
Here are the docs: EJS
If I understand your question correctly this should help.
本文标签: javascriptHow to escape ejs tags inside an ejs template stringStack Overflow
版权声明:本文标题:javascript - How to escape ejs tags inside an ejs template string? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745497320a2660865.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论