我对haml还不熟悉,所以我还在努力弄清楚格式。
我有一个包含以下代码的index.haml文件。
%h1
Welcome to Solidarity
Hello,
= @profile.first_name
!它呈现如下:
欢迎来到团结会 你好,用户!
以下是页面来源:
<h1>
Welcome to Solidarity
</h1>
Hello,
frances
!它在@profile.first_name和感叹号之间有一个空格。为什么会这样呢?那我该怎么解决呢?
发布于 2010-04-26 03:56:10
%h1 Welcome to Solidarity
Hello, #{@profile.first_name}!
Please #{link_to 'post a comment', new_comment_path}!变成了
<h1>Welcome to Solidarity</h1>
Hello, John!
Please <a href="/comments/new">post a comment</a>!请记住,在Rails 2和Haml 2中,您必须正确地使用html-转义发送到浏览器(ht Nex3)的任何内容:
Hello, #{h @profile.first_name}!在Rails 3和Haml 3中,默认情况下都是转义的,因此您可以简单地执行以下操作:
Hello, #{@profile.first_name}!发布于 2010-05-07 12:32:03
你也可以使用“鳄鱼”来“吃”标签前后的空白。来自哈姆兰博士
%img
%pre><
foo
bar
%img汇编如下:
<img /><pre>foo
bar</pre><img />虽然这也解决了这里的问题,但Justice给出的解决方案是这个场景的适当标记。我只是想提一下。
https://stackoverflow.com/questions/2711070
复制相似问题