You need to set the escape_attrs
option to false.
From the command line you can use something like
$ haml --no-escape-attrs my_file.haml
or from Ruby something like:
Haml::Engine.new(my_template, :escape_attrs => false).to_html
题
I'm using Haml outside of Rails and need to print out an unescaped string:
%div{ foo: '<?php echo "bar" %>' }
becomes
<div foo='<?php echo "bar" %>'></div>
but I want
<div foo='<?php echo "bar" %>'></div>
raw
and html_safe
are not defined outside of Rails, I tried requiring them and mixing them in, but the end result was the same.
Maybe I'm missing something obvious here...
解决方案
You need to set the escape_attrs
option to false.
From the command line you can use something like
$ haml --no-escape-attrs my_file.haml
or from Ruby something like:
Haml::Engine.new(my_template, :escape_attrs => false).to_html
其他提示
Well to my understanding there is no easy way to do this. Reference: https://groups.google.com/forum/#!topic/haml/RScABe1Txh8
Seems you will have to do something hackish.
I can only think of writing that specific part in HTML and putting it in :plain
block.