开发者

HAML indentation problem IF

开发者 https://www.devze.com 2023-01-02 07:17 出处:网络
This is my code: -@activities.ea开发者_JS百科ch do |a| -if @i%3 == 0 %ul %li=link_to a.name, a -@i += 1

This is my code:

-@activities.ea开发者_JS百科ch do |a|
  -if @i%3 == 0
    %ul
  %li=link_to a.name, a
  -@i += 1

I need the li to be inside the ul which is inside the if-statement. I can't do it because of the indentation. Can't I just tell the li to indent automatically?

Thanks


I think you would like to output a new %ul each time when @i%3 == 0 and then put the %li tags there. You can do like the following:

-@activities.in_groups_of(3, false) do |activity_group|
  %ul
    -activity_group.each do |activity|
     %li=link_to activity.name, activity

To see more information about the topic please visit: http://railscasts.com/episodes/28-in-groups-of

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号