哈姆尔,块和局部 [英] haml, blocks and partials
本文介绍了哈姆尔,块和局部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要清理并分解丑陋的视图,我想执行以下操作:
To clean and factor ugly views, I'd like to do the following:
1)在视图中:
= document_left_container do
= document_information
2)在我的助手中:
def document_left_container(&block)
render partial: "/document_left_container", locals: { custom_block: block }
end
def document_information
render partial: "document_information"
end
3)局部:
对于document_left_container:
For document_left_container:
.foo
= custom_block.call
对于document_information:
For document_information:
.bar
4)预期结果:
<div class='foo'>
<div class='bar'>
</div>
</div>
5)实际结果:
<div class='foo'>
</div>
<div class='bar'>
</div>
有人知道我该怎么做才能使我的东西正常工作吗?
Does anyone know how I could do to get my stuff working?
预先感谢
本
推荐答案
以下是我将其保持干燥的方式:
Here's how I'd keep it DRY:
=content_for(:document_information) do
.bar
.foo
=yield(:document_information)
这将产生
<div class='foo'>
<div class='bar'>
</div>
</div>
这篇关于哈姆尔,块和局部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文