Skip to main content
Here you can find a list of helper methods provided by Spree that are available in the Storefront. These methods can be used in every template.

Context Helpers

current_store

current_store
Spree::Store
Returns the current store Spree::Store instance.

current_theme

current_theme
Spree::Theme
Returns the current theme Spree::Theme instance.

current_page

Returns the current Spree::Page instance for the current route.
<%= current_page.name %>

current_order

current_order
Spree::Order
Returns the current order object. If no order is found, it will return nil.
Order is automatically created when a user adds a product to the cart.

try_spree_current_user

try_spree_current_user
Spree.user_class
Returns the current user object (class depends on the Spree.user_class configuration). If the user is not signed in, it will return nil.
If you want to check if the user is signed in, you can use the following:
<%= try_spree_current_user.present? %>

current_currency

Returns the currently selected currency. By default in the Storefront this will be store.default_currency. This can be changed in the Settings -> Store Defaults page.
<%= current_currency %>
will return
USD

current_locale

Returns the currently selected locale. By default in the Storefront this will be store.default_locale. This can be changed in the Settings -> Store Defaults page. If there are multiple locales available, it will return the locale that is currently selected by the user.
<%= current_locale %>
Locale also affects the storefront URLs. For example, if the default locale is en and the user selects fr, the URL will be /fr/products/123.

current_taxon

Returns the current taxon when viewing a category/collection page.
<%= current_taxon&.name %>

current_wishlist

Returns the current user’s default wishlist for the current store.
<% if current_wishlist.present? %>
  <%= current_wishlist.wished_items.count %> items
<% end %>

Page Rendering Helpers

render_page

Renders a page with all its sections. This is the main method for rendering page content.
<%= render_page(current_page, pickup_locations: @pickup_locations) %>
Parameters:
  • page - The page to render (defaults to current_page)
  • variables - Hash of variables to pass to section templates

render_section

Renders a single section.
<%= render_section(section, product: @product) %>

render_header_sections

Renders all header sections (announcement bar, header).
<%= render_header_sections %>
Renders all footer sections (newsletter, footer).
<%= render_footer_sections %>

Section & Block Helpers

section_styles

Returns inline CSS styles for a section based on its preferences (padding, colors, borders).
<div style="<%= section_styles(section) %>">
  <!-- Section content -->
</div>

block_attributes

Returns data attributes for a block (used for Page Builder editing).
<h2 <%= block_attributes(block) %>>
  <%= block.text %>
</h2>

page_builder_enabled?

Returns true when the page is being viewed in Page Builder preview mode.
<% cache_unless page_builder_enabled?, cache_key do %>
  <!-- Cached content -->
<% end %>
Renders a link from a Spree::PageLink object.
<%= page_builder_link_to section.link, class: 'btn-primary' %>

<%# With custom content %>
<%= page_builder_link_to section.link do %>
  <span class="icon"></span> Click here
<% end %>

Currency & Price Helpers

supported_currencies

Returns the list of supported currencies for the current store as an array of strings.
<%= supported_currencies %>
will return
["USD", "EUR"]

display_price

Displays a formatted price with currency symbol.
<%= display_price(product.price_in(current_currency)) %>

Date & Time Helpers

local_time

Displays a time in the user’s timezone in a human readable format (based on the browser’s timezone).
<%= local_time(order.sent_to_erp_at) %>
Provided by local_time gem.

URL Helpers

spree_storefront_resource_url

Generates a URL for a Spree resource (product, taxon, post, page).
<%= link_to product.name, spree_storefront_resource_url(product) %>
<%= link_to taxon.name, spree_storefront_resource_url(taxon) %>

spree.nested_taxons_path

Generates a URL for a taxon using its full permalink.
<%= link_to taxon.name, spree.nested_taxons_path(taxon) %>
<%# => /t/categories/clothing/shirts %>

Image Helpers

spree_image_tag

Renders an optimized image tag with automatic WebP conversion and retina support.
<%= spree_image_tag product.images.first,
    width: 400,
    height: 400,
    alt: product.name,
    loading: :lazy %>

spree_image_url

Generates a URL for an image with specified dimensions.
<%= spree_image_url(product.images.first, width: 800, height: 600) %>
See Images & Assets for more details on image helpers.

Product Helpers

taxon_products

Returns products for a given taxon, useful in section templates.
<% taxon_products(section.taxon).limit(4).each do |product| %>
  <%= render 'spree/products/card', product: product %>
<% end %>

storefront_products

Returns products based on current filters and sorting.
<% storefront_products.each do |product| %>
  <%= render 'spree/products/card', product: product %>
<% end %>

Cache Helpers

spree_storefront_base_cache_key

Returns the base cache key for storefront caching.
<% cache [spree_storefront_base_cache_key, product] do %>
  <%= render 'product_card', product: product %>
<% end %>

spree_storefront_base_cache_scope

Returns a cache scope proc for section caching.
<% cache_unless page_builder_enabled?, spree_storefront_base_cache_scope.call(section) do %>
  <!-- Section content -->
<% end %>

Preview Helpers

These helpers are used for Page Builder preview functionality:
HelperDescription
current_theme_previewReturns the theme preview if in preview mode
current_page_previewReturns the page preview if in preview mode
current_theme_or_previewReturns theme preview or active theme
current_page_or_previewReturns page preview or active page