\n ERB 中的新行转义序列
我不确定为什么“\n\n”不在我的代码中添加两个换行符:
<%= (getparagraph(@geography, "geography")+"\n\n") if @geography != "Other" %>
为了澄清方法 getparagraphs 只是返回一段文本。我正在尝试在 Ruby 代码中添加两个换行符,而无需使用
有什么想法吗?我读过的所有内容都表明它应该有效。
I'm not sure why "\n\n" is not adding two line breaks in my code below:
<%= (getparagraph(@geography, "geography")+"\n\n") if @geography != "Other" %>
To clarify the method getparagraphs simply returns a paragraph of text. I'm trying to add two line breaks within the Ruby code without having to use <br/>
Any ideas? Everything I've read implies that it should work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
狠疯拽2024-12-21 17:35:42
您的帮助程序的名称中包含“paragraph”,因此也许您应该将其包装在一个段落中,并使用 CSS 在段落周围添加适当的间距:
<% if @geography != "Other" %>
<p>
<%= getparagraph(@geography, "geography") %>
</p>
<% end %>
您始终可以向
添加一个特殊的类如果您在此之后需要额外的间距:
<% if @geography != "Other" %>
<p class="geo-chunk">
<%= getparagraph(@geography, "geography") %>
</p>
<% end %>
然后在您的 CSS 中:
.geo-chunk {
margin-bottom: 2em; /* Or whatever works */
}
如果这是出现在另一个
中,那么您需要尽可能地重新排列 HTML不要将块元素放入 a 中
:
<div>
<!-- The old <p> content ... -->
<% if @geography != "Other" %>
<div class="geo-chunk">
<%= getparagraph(@geography, "geography") %>
</div>
<% end %>
</div>
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
这是在 HTML 中吗?如果是这样,那么只需使用
。 HTML 会忽略多个空白字符,因此您可以有 1 个空格或 50 个换行符,结果都是相同的。另请注意:除非您使用 XHTML(本身不是一个好主意),否则不要使用自闭合标记,例如
。斜杠无效,因此省略它。Is this within HTML? If so, then just use
<br>
. HTML ignores multiple whitespace characters, so you could have one space or 50 newlines and the result would be the same.Another note: unless you're using XHTML (itself not a great idea), do not use self-closing tags such as
<br/>
. The slash is invalid, so omit it.