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
blocks_available? and available_blocks_to_add methods.
Built-in Block Types
Spree comes with several built-in block types:Content Blocks
Navigation 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) viaSpree::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: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:Block with Links
To add link support to your block, include theSpree::HasOneLink concern:
Block with Image
Blocks automatically have anasset attachment available:

