多行换行似乎对我不起作用:
就像是:
intro: |
We are happy that you are interested in
and
more
and + more 需要在换行符上,但它失败了。
intro: |
| We are happy that you are interested in
| and
| more
或者
intro: |
We are happy that you are interested in \n
and
more <2 spaces >
another one
都失败了。
如何在 yaml 文本块中正确使用多行?
我在 Rails 应用程序的 HAML View 中使用它,例如
= t("mailer.beta_welcome.intro")
但是没有以这种方式打印换行符,我是否需要使用 raw 或其他方式以不同的方式输出它?
最佳答案
你的第一个例子工作正常
文件名
intro: |
We are happy that you are interested in
and
more
文件名
require 'yaml'
puts YAML.load_file('foo.yml').inspect
输出
{"intro"=>"We are happy that you are interested in\nand \nmore\n"}
关于syntax - 如何正确拥有多行 yaml 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19959823/