sam*_*207 4 layout partial liquid ruby-on-rails-3
我有一个液体模板,我需要在其中渲染部分内容.
请注意@current_page.page_layout.content将从数据库加载内容
我的液体布局文件如下
#layouts/public.html.erb
<%= Liquid::Template.parse(@current_page.page_layout.content).
render('page_content' => yield, 'page_title' => yield(:title)) %>
Run Code Online (Sandbox Code Playgroud)
以下是我的代码,其中包括部分代码
{{page_content}}
{% include 'this_is_the_partial_name' %}
Run Code Online (Sandbox Code Playgroud)
而且我收到了这个错误
Liquid error: This liquid context does not allow includes.
Run Code Online (Sandbox Code Playgroud)
我试过谷歌并找到了这个解决方案,但我仍然不确定此代码的输入位置/内容
Liquid::Template.file_system =
Liquid::LocalFileSystem.new(template_path)
liquid = Liquid::Template.parse(template)
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激
提前致谢
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)
Run Code Online (Sandbox Code Playgroud)
Add your partial file, eg. app/views/snippets/_partial_name.liquid.
Now in your liquid template use:
{% include 'partial_name' %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2753 次 |
| 最近记录: |