Created
August 16, 2011 12:29
-
-
Save anoras/1148957 to your computer and use it in GitHub Desktop.
LiquidTemplatedController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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