ruby-on-rails – 如何使用Liquid模板语言在布局中渲染模板?
发布时间:2020-12-17 01:19:47 所属栏目:百科 来源:网络整理
导读:我正在尝试在液体布局中渲染液体模板(液体模板朗,而不是CSS液体布局的东西).我似乎无法获得渲染的布局部分.目前使用: assigns = {'page_name' = 'test'}@layout = Liquid::Template.parse(File.new(@theme.layout.path).read)@template = Liquid::Template.
我正在尝试在液体布局中渲染液体模板(液体模板朗,而不是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,一切都按预期工作.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |