我正在使用部分构建面板,但我想用一些html自定义面板内部。有没有办法为哈希值编写一些HTML?
我有一个自定义的部分 _panel_builder.html.erb ,我将其作为参数pclass
,heading
,body
等,我希望像这样使用:
(以下语法不好,但我真的不明白我怎么能做点好事......)
<% @etudes.each_with_index do |etude, i| %>
<%= render 'shared/panel_builder',
pclass: panel_color_rotation(i),
heading: etude.name,
# For the body param, I'd like to be able to use some HTML with occasional <%=...%> for variables, like :
body: (%>
<p><%=etude.description %></p>
<ul>
<%etude.competences.each do |comp| %>
<li><strong><%= competence.name %></strong> : <%=competence.level %>
<br><small><%=competence.why %></small>
</li>
<% end %>
</ul>
<%).html_safe,
collapsable: true %>
<% end %>
编辑:了解我的 _panel_builder 部分内容:
<%
collapsable ||= false
pclass ||= "default"
footer ||= false
%>
<div class="panel panel-<%= pclass %> <%= if collapsable then "panel-collapsable " end %>">
<div class="panel-heading">
<%= heading %>
<% if collapsable %>
<span class="pull-right"><i class="glyphicon glyphicon-chevron-down"></i></span>
<% end %>
</div>
<div class="panel-body <%= if collapsable then "collapse" end %>">
<%= body %>
</div>
<% if footer %>
<div class="panel-footer <%= if collapsable then "collapse" end %>">
<%= footer %>
</div>
<% end %>
</div>
答案 0 :(得分:0)
好的,所以我实际上在寻找capture
帮手:
<% @etudes.each_with_index do |etude, i| %>
<%= render 'shared/panel_builder',
pclass: panel_color_rotation(i),
heading: etude.name,
body: capture do %>
<p><%=etude.description %></p>
<ul>
<%etude.competences.each do |comp| %>
<li><strong><%= competence.name %></strong> : <%=competence.level %>
<br><small><%=competence.why %></small>
</li>
<% end %>
</ul>
<% end %>,
collapsible: true %>
<% end %>
注意:在某些情况下,我还想传递一个复杂的HTML块作为页脚的标题,所以我不能只有一个需要一个块的帮助器。
注意2:我的面板是为通用数据制作的HTML模板。我无法将它传递给Ruby对象