[英]How do I format HTML, removing unwanted line breaks?
I would like to do something like this: 我想做这样的事情:
<div class="show_details_block">
<% if @model.details.length > 0 then %>
<%= h(@model.details) %>
<% else %>
"No details available"
<% end %>
</div>
However, this adds unwanted line breaks to my HTML source. 但是,这会为我的HTML源添加不需要的换行符。 I would prefer to avoid writing it inline like this:
我宁愿避免像这样写内联:
<div class="show_details_block"><% if @task.details.length <= 0 then %>"No details available"<% else %><%= h(@task.details) %><% end %></div>
Can I maintain my code formatting/styling without having to face the consequences of unwanted line breaks? 我可以维护我的代码格式/样式而不必面对不必要的换行的后果吗?
Haml counterpart: Haml对应:
.show_details_block
- if @model.details.length > 0 then
= h(@model.details)
- else
No details provided..
ERB allows you to use <%-
and -%>
around your code interpolation. ERB允许您在代码插值周围使用
<%-
和-%>
。 These forms suppress the line-breaks before or after the start/end interpolation marks. 这些形式抑制了开始/结束插值标记之前或之后的换行符。 See the description of trim-mode in
ERB::new
请参阅
ERB::new
的trim-mode描述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.