Skip to content

Instantly share code, notes, and snippets.

@sgruhier
Created September 21, 2011 07:06
Show Gist options
  • Save sgruhier/1231441 to your computer and use it in GitHub Desktop.
Save sgruhier/1231441 to your computer and use it in GitHub Desktop.
Rails 3.1 version of extra/liquid_view.rb of liquid markup gem
class LiquidHandler
PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template
_response url _request _cookies variables_added _flash params _headers request cookies
ignore_missing_templates flash _params logger before_filter_chain_aborted headers )
def self.call(template)
new.compile(template)
end
def compile(template)
<<-LIQUID
variables = assigns.reject{ |k,v| LiquidHandler::PROTECTED_ASSIGNS.include?(k) }
if content_for_layout = instance_variable_get("@content_for_layout")
variables['content_for_layout'] = content_for_layout
end
variables.merge!(local_assigns.stringify_keys)
liquid = Liquid::Template.parse("#{template.source.gsub(/\"/, '\\\"')}")
liquid.render(variables, :registers => {:action_view => self, :controller => controller})
LIQUID
end
end
::ActionView::Template.register_template_handler(:liquid, LiquidHandler)
@neerajsingh0101
Copy link

This code is working fine for regular files. However for layouts content_for_layout did not work. Here is my layout . http://pastie.org/2747749

Any suggestions. Thanks.

@railsfactory-kalaivani
Copy link

Hi,
I am new to rails.I heard a about the liquid template concept. Can any one tell me how to implement the liquid template in the project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment