【问题标题】:Rendering a partial in liquid layout (Rails3)渲染部分液体布局(Rails3)
【发布时间】:2013-02-11 18:45:57
【问题描述】:

我有一个液体模板,我需要在其中渲染一部分。

请注意@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)) %>

以下是我的代码,其中也包括部分代码

{{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) 

【问题讨论】:

    标签: ruby-on-rails-3 layout partial liquid


    【解决方案1】:

    晚会有点晚了..但这是你应该如何使用它:

    在初始化程序(如 /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' %}
    

    【讨论】:

      猜你喜欢
      • 2012-11-15
      • 1970-01-01
      • 1970-01-01
      • 2011-06-12
      • 1970-01-01
      • 1970-01-01
      • 2012-10-17
      • 1970-01-01
      • 2015-01-06
      相关资源
      最近更新 更多