简体   繁体   English

如何在从yaml加载的文本中插入换行符?

[英]How do I insert a line break into text loaded from yaml?

I'm using Ruby v.1.8.7 and Rails v.3.1.3 to create a website and I'm loading the text on the pages from a yml file. 我正在使用Ruby v.1.8.7和Rails v.3.1.3来创建一个网站,我正在从yml文件中加载页面上的文本。 I have text inside of a <h3> tag but I want the third sentence to be placed on a separate line without having to do an explicit check in the html. 我有一个<h3>标签内的文本,但我希望将第三个句子放在一个单独的行上而不必在html中进行显式检查。

For instance, I have: 例如,我有:

<h3><%= Settings.text_from_yml %></h3>

in my view and text_from_yaml looks like: 在我看来,text_from_yaml看起来像:

This is the first sentence. This is the second. And lastly, the third.

inside the yml file. 在yml文件中。 Is there a way I can place a line break in the string inside the yml file to guarantee the third sentence will be on its own line? 有没有办法我可以在yml文件中的字符串中放置一个换行符,以保证第三个句子将在它自己的行上? I've tried placing <br /> before the third line but that just outputs the text " <br /> And lastly, the third. " 我试过在第三行之前放置<br />但是只输出文本“ <br /> And lastly, the third.

I've also tried doing 我也尝试过

<h3><%= Settings.text_from_yml.html_safe %></h3>

but that didn't do what I wanted. 但那没有做我想要的。 Is there some other way to accomplish this? 有没有其他方法来实现这一目标?

<h3><%= raw Settings.text_from_yml %></h3>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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