Sha256: 01fc5ee61adc692f39c798f03e90d46629766b2dc66435794ea001153e847b0b

Contents?: true

Size: 930 Bytes

Versions: 6

Compression:

Stored size: 930 Bytes

Contents

module Locomotive
  module Liquid
    module Tags

      # 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>
      #
      class FetchPage < ::Liquid::Tag

        Syntax = /(#{::Liquid::VariableSignature}+)\s+as\s+(#{::Liquid::VariableSignature}+)/

        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

        def render(context)
          context.scopes.last[@var] = context.registers[:site].pages.where(handle: @handle).first
          ''
        end
      end

      ::Liquid::Template.register_tag('fetch_page', FetchPage)
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
locomotive_cms-2.5.7 lib/locomotive/liquid/tags/fetch_page.rb
locomotivecms-3.0.0.pre.alpha.2 lib/locomotive/previous_liquid/tags/fetch_page.rb
locomotivecms-3.0.0.pre.alpha lib/locomotive/previous_liquid/tags/fetch_page.rb
locomotive_cms-2.5.6 lib/locomotive/liquid/tags/fetch_page.rb
locomotive_cms-2.5.6.rc2 lib/locomotive/liquid/tags/fetch_page.rb
locomotive_cms-2.5.6.rc1 lib/locomotive/liquid/tags/fetch_page.rb