2013-02-11 125 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