我正在尝试在液体布局中渲染液体模板(液体模板语言,而不是 CSS 液体布局内容)。我似乎无法渲染布局部分。目前使用:
assigns = {'page_name' => 'test'}
@layout = Liquid::Template.parse(File.new(@theme.layout.path).read)
@template = Liquid::Template.parse(File.new(self.template.path).read)
@rend_temp = @template.render(assigns)
@rend_layout = @layout.render({'content_for_layout' => @rend_temp})
render :text => @rend_layout, :content_type => :html
页面的 HTML 显示“模板”在液体中渲染得很好,但它没有被布局包裹(用渲染的模板替换布局中的“content_for_layout”)
只是为了让其他人知道谁遇到了这个问题,上面发布的代码实际上确实有效,问题在于名为 @template 的变量。我将@template和@layout重命名为@_tempalte和@_layout,一切都按预期工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)