Skip to main content
Blocks are the lowest level of components in Spree Storefront. They are nested inside sections and represent individual content elements like headings, text, buttons, and images.

How Blocks Work

Each section can contain multiple blocks that store staff can manage through the Page Builder:
  • Add new blocks
  • Edit block content and settings
  • Reorder blocks via drag-and-drop
  • Remove blocks
Not all sections support blocks. A section must explicitly enable block support by implementing blocks_available? and available_blocks_to_add methods.

Built-in Block Types

Spree comes with several built-in block types:

Content Blocks

Product Blocks

These blocks are used in the Product Details section:

Architecture

Base Class

All blocks inherit from Spree::PageBlock:

Default Preferences

Every block has these default preferences:

Associations

  • Section: Each block belongs to a section (section)
  • Links: Blocks can have multiple links (links) via Spree::HasPageLinks
  • Asset: Blocks can have an attached image (asset)
  • Rich Text: Blocks can have rich text content (text)

Accessing Blocks

Rendering Blocks

In storefront section views, blocks are rendered within their parent section:
The block_attributes(block) helper returns data attributes needed for Page Builder editing.

Creating a Custom Block

Step 1: Create the Model

app/models/spree/page_blocks/quote.rb

Step 2: Register the Block

config/initializers/spree.rb

Step 3: Add to Section’s Available Blocks

In your section model, add the new block type:

Step 4: Create Admin Form

app/views/spree/admin/page_blocks/forms/_quote.html.erb

Step 5: Render in Section View

Add rendering logic to your section’s storefront view:
To add link support to your block, include the Spree::HasOneLink concern:

Block with Image

Blocks automatically have an asset attachment available:

Key Methods

  • Sections - Parent containers for blocks
  • Links - Adding links to blocks
  • Media - Working with images