sameera207
sameera207

Reputation: 16629

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) 

Upvotes: 4

Views: 3690

Answers (1)

joost
joost

Reputation: 6659

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' %}

Upvotes: 11

Related Questions