我有一个小部件的Slim部分。窗口小部件有共同的元素,然后是我想要屈服的一些自定义内容。那个正确的语法是什么?这是我认为可行的,但不是。
Widget Partial
.container
.title= title
.content
== yield
页
.page
= render partial: "widget_partial", locals: { title: "Content 1" } do
div Some really awesome content.
= render partial: "widget_partial", locals: { title: "Content 2" } do
span Different but also awesome content.
答案 0 :(得分:1)
根据部分Action View Overview(第3.2.3节),当你只使用部分模板和本地人时,你可以采用这样的最小方法:
(小部件)
.container
.title
p #{title}
= yield
(页)
= render "widget_partial", title: "content 1" do
.div
p Some really awesome content.
= render "widget_partial", title: "content 2" do
.div
p Different but also awesome content.
请注意,在partial本身中,您不能直接将文本放入
div
,所以我添加了<p>
元素。
答案 1 :(得分:0)
您应该在layout
中添加render
参数。像这样:
(小部件)
.container
.title = title
.content
= yield
(页)
.page
= render layout: 'widget_partial', locals: { title: 'Content 1' } do
div Some really awesome content.
= render layout: 'widget_partial', locals: { title: 'Content 2' } do
span Different but also awesome content.
Doc:http://edgeguides.rubyonrails.org/action_view_overview.html#partial-layouts