Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering a partial in liquid layout (Rails3)

I have a liquid template where I need to render a partial inside that.

Please note @current_page.page_layout.content will load the content from the DB.

My liquid layout file is as follows:

#layouts/public.html.erb
<%= Liquid::Template.parse(@current_page.page_layout.content).
render('page_content' => yield, 'page_title' => yield(:title)) %>

and following is my code, which includes the partial as well

{{page_content}}

{% include 'this_is_the_partial_name' %}

and I'm getting this error

Liquid error: This liquid context does not allow includes.

I tried searching the web and found this solution, but still I'm not sure what to enter for this code:

Liquid::Template.file_system = 
Liquid::LocalFileSystem.new(template_path) 
liquid = Liquid::Template.parse(template) 
like image 220
sameera207 Avatar asked Dec 20 '22 09:12

sameera207


1 Answers

Little late to the party.. but this is how you should use it:

In an initializer (like /config/initializers/liquid.rb) add:

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

Add your partial file, eg. app/views/snippets/_partial_name.liquid.

Now in your liquid template use:

{% include 'partial_name' %}
like image 195
joost Avatar answered Jan 05 '23 06:01

joost