我們如何才能逃避模板內的ejs標籤?如何逃避ejs模板字符串內的ejs標籤?
在船帆我願把下面的代碼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-->
但默認情況下,所有的<!--STYLES-->
和<!--STYLES END-->
裏面的東西被此模板取代:
<link rel="stylesheet" href="%s">
與sails-linker.js
中一樣。
所以不是模板<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-->
但問題是,當我嘗試像
<%= special_code_here %><link rel="stylesheet" href="%s">
這是自動呈現的。我需要逃避ejs模板中的<%
。
我們該怎麼做?
您是否嘗試過'<' and '>'的HTML實體,它們是'<'和'>'? –
@ScottMarcus是的,我試過了。這個問題被呈現爲layout.ejs文件中的html實體,在那裏我應該有非轉義的'<%'。所以在瀏覽器中出現我想要的代碼,但是作爲純文本。 – GarouDan