如何使用Liquid模板语言在布局中渲染模板?

bwi*_*zzy 8 ruby-on-rails liquid

我正在尝试在液体布局中渲染液体模板(Liquid Template lang,而不是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
Run Code Online (Sandbox Code Playgroud)

页面生成的HTML显示"模板"以流畅的方式呈现,但不包含布局(使用呈现的模板替换布局中的"content_for_layout")

bwi*_*zzy 7

只是为了让其他人知道谁遇到这个问题,上面发布的代码实际上确实有效,问题在于名为@template的变量.我将@template和@layout重命名为@_tempalte和@_layout,一切都按预期工作.