简体   繁体   中英

Is there a way to write a single expression over multiple lines in haml?

I have this in one of my haml views:

-form_for :news_item_comment, :url=>{:id => comment.id, :controller => 'comment' , :action => 'add_comment'}, :html => {:id => "form-#{comment.id}"}  do |f|    
   ...

Since it's really long and hard to read I want to split it over 2 lines. Is there anyway to do this without violating haml's whitespace rules?

Yes, there is multiline syntax . However, it's encouraged that you move your long lines into helper methods rather than use it, as that will make your templates more readable in the long run.

In earlier versions of haml there was no way to multi-line a single statement - something which I was frustrated with in the same way you are as it made templates way harder to read in some cases.

In theory there is a multi-line syntax for handling statements with lots of attributes. I have not tried to use it - but it's worth a shot, if that doesn't work then it is likely still the case that you cannot multi-line that type of statement.

The '|' can be used as a line separator for multi line syntax.Refer this http://www.mail-archive.com/haml@googlegroups.com/msg04722.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM