Skip to content

Instantly share code, notes, and snippets.

@anoras
Created August 16, 2011 12:29
Show Gist options
  • Select an option

  • Save anoras/1148957 to your computer and use it in GitHub Desktop.

Select an option

Save anoras/1148957 to your computer and use it in GitHub Desktop.
LiquidTemplatedController
class LiquidTemplatedController < ApplicationController
include Locomotive::Routing::SiteDispatcher
include Locomotive::Render
before_filter :require_site
protected
def render_with_template(*args)
template_path = args.select {|arg| arg.is_a?(Hash) && arg.has_key?(:template_path)}.first[:template_path] rescue 'index'
args.reject! {|arg| arg.is_a?(Hash) && arg.has_key?(:template_path)}
page_partial = render_to_string(*args)
stored_page = nil
stored_page = @page unless @page.nil?
@page = current_site.pages.any_in(:fullpath => [template_path]).first
context = locomotive_context
context.merge({
'yield' => page_partial
})
output = @page.render(context)
@page = stored_page unless stored_page.nil?
render :text => output
end
end
<html>
<head>
</head>
<body>
<span>This text will appear before the Rails view...</span>
{{ yield }}
<span>This text will appear after the Rails view...</span>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment