diff --git a/app/models/smithy/page.rb b/app/models/smithy/page.rb index a5d40b7..ac411c6 100644 --- a/app/models/smithy/page.rb +++ b/app/models/smithy/page.rb @@ -21,6 +21,7 @@ class Page < ActiveRecord::Base scope :published, -> { where('published_at <= ?', Time.now) } attr_accessor :publish + attr_accessor :liquid_registers def container?(container_name) containers.where(:name => container_name).count > 0 @@ -44,10 +45,15 @@ def published? self.published_at? end + def render(liquid_context) + @liquid_registers = liquid_context.registers + self.template.liquid_template.render(liquid_context) + end + def render_container(container_name) return '' unless container?(container_name) Rails.cache.fetch(self.container_cache_key(container_name)) do - self.contents_for_container_name(container_name).map(&:render).join("\n\n") + self.contents_for_container_name(container_name).map{|c| c.render(liquid_registers) }.join("\n\n") end end diff --git a/app/models/smithy/page_content.rb b/app/models/smithy/page_content.rb index f28dc6d..1b55408 100644 --- a/app/models/smithy/page_content.rb +++ b/app/models/smithy/page_content.rb @@ -31,8 +31,8 @@ def content_block_attributes=(attributes) end end - def render - content_block_template.liquid_template.render(self.to_liquid) + def render(liquid_registers) + content_block_template.liquid_template.render(::Liquid::Context.new({}, self.to_liquid, liquid_registers, !Rails.env.production?)) end def to_liquid