Class: Locomotive::Liquid::Tags::FetchPage
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Locomotive::Liquid::Tags::FetchPage
- Defined in:
- lib/locomotive/liquid/tags/fetch_page.rb
Overview
Fetch a page from its handle and assign it to a liquid variable.
Usage:
fetch_page ‘about_us’ as a_page % <p>a_page.title }</p>
Constant Summary collapse
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens, context) ⇒ FetchPage
constructor
A new instance of FetchPage.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens, context) ⇒ FetchPage
Returns a new instance of FetchPage.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/locomotive/liquid/tags/fetch_page.rb', line 16 def initialize(tag_name, markup, tokens, context) if markup =~ Syntax @handle = $1 @var = $2 else raise SyntaxError.new("Syntax Error in 'fetch_page' - Valid syntax: fetch_page page_handle as variable") end super end |
Instance Method Details
#render(context) ⇒ Object
27 28 29 30 |
# File 'lib/locomotive/liquid/tags/fetch_page.rb', line 27 def render(context) context.scopes.last[@var] = context.registers[:site].pages.where(handle: @handle).first '' end |