有 html 代码加了 js 后好像可以动态写一些 template,如
<%for(var i=0,il=data.length;i<il> ... <p>这个时候在 erb 文件里面会有问题,改成<%% xxx %>即可,这种双百分号是啥个意思?我肯定漏了哪个基础知识哈。</p> </il>
From https://github.com/jnicklas/templater#templates:
If you need to render templates where the result should contain actual erb, simply use a double percentage sign, this will prevent the statement from being executed.
例如:
<%= 2+2 %>
输出 4
<%%= 2+2 %>
输出 <%= 2+2 %>
可以避免执行 erb
#1 楼 @ywjno <%== something %>
是<%= raw something %>
的简写。见:http://edgeguides.rubyonrails.org/active_support_core_extensions.html#output-safety
To insert something verbatim use the
raw
helper rather than callinghtml_safe
:<%= raw @cms.current_template %> <%# inserts @cms.current_template as is %>
or, equivalently, use
<%==
:<%== @cms.current_template %> <%# inserts @cms.current_template as is %>