ruby-on-rails-3 – 渲染部分液体布局(rails3)
发布时间:2020-12-17 03:47:29 所属栏目:百科 来源:网络整理
导读:我有一个液体模板,我需要在其中渲染部分内容. 请注意@ current_page.page_layout.content将从数据库加载内容 我的液体布局文件如下 #layouts/public.html.erb%= Liquid::Template.parse(@current_page.page_layout.content).render('page_content' = yield,'
我有一个液体模板,我需要在其中渲染部分内容.
请注意@ current_page.page_layout.content将从数据库加载内容 我的液体布局文件如下 #layouts/public.html.erb <%= Liquid::Template.parse(@current_page.page_layout.content). render('page_content' => yield,'page_title' => yield(:title)) %> 以下是我的代码,其中包括部分代码 {{page_content}} {% include 'this_is_the_partial_name' %} 而且我收到了这个错误 Liquid error: This liquid context does not allow includes. 我试过谷歌和found this solution,但我仍然不确定这个代码在哪里/什么输入 Liquid::Template.file_system = Liquid::LocalFileSystem.new(template_path) liquid = Liquid::Template.parse(template) 任何帮助将不胜感激 提前致谢 解决方法
晚会很晚..但这是你应该如何使用它:
在初始化程序(如/config/initializers/liquid.rb)中添加: template_path = Rails.root.join('app/views/snippets') Liquid::Template.file_system = Liquid::LocalFileSystem.new(template_path) 添加您的部分文件,例如.应用程序/视图/段/ _partial_name.liquid. 现在在您的液体模板中使用: {% include 'partial_name' %} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |