开发者

A html string is escaped in haml file

开发者 https://www.devze.com 2023-02-04 13:12 出处:网络
#test - html = \"<a href=\'http://www.a.com\'>Test</a>\" = html The output is <div id=\'test\'>
#test
  - html = "<a href='http://www.a.com'>Test</a>"
  = html

The output is

<div id='test'>
  &lt;a href='http://www.a.com'&gt;Test&lt;/a&gt;
</div>

But I want a output:

<div id='test'>
  <a href='http://开发者_开发百科www.a.com'>Test</a>
</div>

Anyone has solutions? Thanks.


haml also provides with its equivalent tag to rails 3's raw method: !=, eg:

!= html


= raw html

or:

= html.html_safe


There was a change in rails 3 so that all content is now html escaped by default. See this blog post from Yehuda Katz for more details.

In order to print the html directly you need to use html_safe on your variable:

#content
 .title
   %h1= @title
   = @content.html_safe

For a more complex example, see this answer to a similar question.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号