简体   繁体   English

Rails 3 / HAML:如何从变量输出haml raw?

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

I have some variables within rails that contain some divs like so: 我在rails中有一些包含一些div的变量,如下所示:

@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 ? 这是来自数据库,我们的想法是根据请求交换布局,但是如何在HAML文件中输出变量( @layout_1 )作为HAML?

If I were to use normal html divs, I would use <%=raw or .html_safe 如果我使用普通的html div,我会使用<%=raw.html_safe

you would do the same with HAML as well in your .html.haml view file. 您也可以在.html.haml视图文件中使用HAML。

= raw @layout_1

or 要么

= @layout_1.html_safe

Not entirely sure this works, but give it a try: 不完全确定这是有效的,但尝试一下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM