Module: PrismicRails::ViewHelpers

Defined in:
lib/prismic_rails/helpers/view_helpers.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#prismic_type(type, options = {}, &block) ⇒ Object

Query prismic for a specific type

Examples:

Query the prismic type ‘blog-post’ and render each document as html

<% prismic_type 'blog-post' do |result| %>
  <%- result.documents.each do |document| %>
    <%= document.to_html %>
  <% end %>
<% end %>

Query the prismic type ‘blog-post’ in english

<% prismic_type 'blog-post', lang: 'en' do |result| %>
  <%- result.documents.each do |document| %>
    <%= document.to_html %>
  <% end %>
<% end %>

Query only the title of the type ‘blog-post

<% prismic_type 'tea' do |result| %>
  <%= result.find_fragment('title').to_html %>
<% end %>

Supports Rails caching if the caching is enabled



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/prismic_rails/helpers/view_helpers.rb', line 33

def prismic_type(type, options = {}, &block)

  query = Proc.new do
    result = PrismicRails::QueryService.by_type(type, options)
    capture(result, &block)
  end

  if PrismicRails.caching_enabled?
    Rails.cache.fetch [PrismicRails.ref, options] do
      query.call
    end
  else
    query.call
  end
end