我正在努力解决haml而不是在正确的位置注入内容,这里是haml的一部分:
%div.form-group{:id => 'container'}
- if !@data.nil?
%p= t('users.data_name')
= link_to t('users.delete'), 'javascript:void(0)', :class => 'delete', :data => {:id => @data.id}
%div.holder.thick
= image_tag @data.path
- else
= link_to t('users.upload'), 'javascript:void(0)', :class => 'btn btn-large'
%div.holder
= image_tag '/assets/missing_image.png'
问题是holder
或holder thick
不在我的容器内但在外面。为什么是这样?我没有正确对齐什么?
答案 0 :(得分:3)
是的,if
如果要将其内容放入#container
,则应缩进。
#container.form-group
- if !@data.nil?
%p= t('users.data_name')
= link_to t('users.delete'), 'javascript:void(0)', :class => 'delete', :data => {:id => @data.id}
.holder.thick
= image_tag @data.path
- else
= link_to t('users.upload'), 'javascript:void(0)', :class => 'btn btn-large'
.holder
= image_tag '/assets/missing_image.png'
答案 1 :(得分:0)
如果你的容器是%div.form-group
,那么你只需缩进其余部分,以便haml理解你的内容应该在div内部
所以它看起来像那样
%div.form-group{:id => 'container'}
- if !@data.nil?
%p= t('users.data_name')
= link_to t('users.delete'), 'javascript:void(0)', :class => 'delete', :data => {:id => @data.id}
%div.holder.thick
= image_tag @data.path
- else
= link_to t('users.upload'), 'javascript:void(0)', :class => 'btn btn-large'
%div.holder
= image_tag '/assets/missing_image.png'