开发者

html entities in haml

How do you write:

= link_to 'Select »', "/" 

in HAML properly?

= link_to 'Select »', "/" 

ju开发者_高级运维st prints » again.

ANSWER FROM Phrogz

= link_to('Select »'.html_safe,'/')

did the trick


In the simplest test, Haml does not futz with your HTML entities:

> require "haml"
#=> true
> Haml::Engine.new('%p= "See »"').render
#=> "<p>See &raquo;</p>\n"

Your problem is probably not Haml, but rather explicit HTML escaping with link_to or Rails itself.

For example, see this question and also:
Ruby on Rails seems to be auto-escaping html created by link_to

If you are using Haml with Rails, perhaps try:

= raw link_to('Select &raquo;','/')

Alternatively, I would just use proper Unicode throughout your pipeline so that there is no chance that an & will be turned into &amp; accidentally.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜