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)
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' %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With