jakobk
jakobk

Reputation: 1132

Rails 3 / HAML: How can I output haml raw from a variable?

I have some variables within rails that contain some divs like so:

@layout_1 = "
.box_1 
.column_4 <br>
.gutter<br>
.column_4<br>
.gutter<br>
.column_4<br>
.gutter<br>
.column_4<br>"

This is coming from a database, and the idea is to swap layouts on request, but how can I output the variable (@layout_1) as HAML inside a HAML file ?

If I were to use normal html divs, I would use <%=raw or .html_safe

Upvotes: 4

Views: 6899

Answers (2)

Aditya Sanghi
Aditya Sanghi

Reputation: 13433

you would do the same with HAML as well in your .html.haml view file.

= raw @layout_1

or

= @layout_1.html_safe

Upvotes: 11

Pedro Nascimento
Pedro Nascimento

Reputation: 13886

Not entirely sure this works, but give it a try:

- output = Haml::Engine.new(@layout1).render
!= output

Upvotes: 5

Related Questions