HAML中的多行字符串 [英] Multiline string in HAML
问题描述
因为我不希望任何行都超过80列,所以我想将最后一行分成两行.按照建议的
Because I don't want any of my lines to be wider than 80 columns, I want to split the last line into two lines. Adding a comma at the end of the line works as suggested here but then the comma appears inside the string. Is there a nice and clean way of doing this with HAML?
- if object.errors.any?
%section.form_error_message
%h4.form_error_message__title
= "#{pluralize(object.errors.size, 'errors')} prevented this form from submitting. Please fix these errors and try again."
我希望将它们全部塞入该屏幕截图左侧的80列中.
I want it all to be tucked inside 80 columns like they are on the left of this screenshot.
推荐答案
Haml支持多行序列使用|
字符:
- if object.errors.any?
%section.form_error_message
%h4.form_error_message__title
= "#{pluralize(object.errors.size, 'errors')} prevented this form from |
submitting. Please fix these errors and try again." |
在这种情况下,您实际上并不需要它,您可以直接使用插值以纯文本格式,您不需要=
:
In this case you don’t really need this though, you can use interpolation directly in plain text, you don’t need the =
:
- if object.errors.any?
%section.form_error_message
%h4.form_error_message__title
#{pluralize(object.errors.size, 'errors')} prevented this form from
submitting. Please fix these errors and try again.
(此命令的输出会稍有不同,因为它将包含换行符.不过,除非在例如<pre>
标记内,否则您不会在呈现的HTML中注意到这一点.)
(The output of this will be slightly different, as it will include the newline. You should’t notice that in the rendered HTML though, unless you are e.g. inside <pre>
tags.)
这篇关于HAML中的多行字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!