Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html entities in haml

How do you write:

= link_to 'Select »', "/" 

in HAML properly?

= link_to 'Select »', "/" 

just prints » again.

ANSWER FROM Phrogz

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

did the trick

like image 426
corroded Avatar asked Apr 06 '11 17:04

corroded


1 Answers

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.

like image 175
Phrogz Avatar answered Oct 04 '22 09:10

Phrogz