2013-02-11 197 views
4

我有一个液体模板,我需要渲染一个局部的内部。渲染局部液体布局(rails3)

请注意@current_page.page_layout.content将从DB

我的液体布局文件如下

#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) 

进入任何帮助,将不胜感激提前

回答

9

小晚

感谢到派对..但这是你应该如何使用它:

在初始化程序(如/config/initializers/liquid.rb)中添加:

template_path = Rails.root.join('app/views/snippets') 
Liquid::Template.file_system = Liquid::LocalFileSystem.new(template_path) 

添加您的文件,例如。 app/views/snippets/_partial_name.liquid

现在您的液体模板使用:

{% include 'partial_name' %} 
+0

该解决方案为我工作。 – 2015-03-25 15:36:56