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.Documentation Index
Fetch the complete documentation index at: https://spreecommerce.org/docs/llms.txt
Use this file to discover all available pages before exploring further.
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
| Block | Description | Class |
|---|---|---|
| Heading | Large text headings | Spree::PageBlocks::Heading |
| Subheading | Smaller secondary headings | Spree::PageBlocks::Subheading |
| Text | Rich text content | Spree::PageBlocks::Text |
| Buttons | Call-to-action buttons with links | Spree::PageBlocks::Buttons |
| Image | Image with optional link | Spree::PageBlocks::Image |
Navigation Blocks
| Block | Description | Class |
|---|---|---|
| Nav | Simple navigation links | Spree::PageBlocks::Nav |
| Mega Nav | Mega menu navigation | Spree::PageBlocks::MegaNav |
| Link | Single link item | Spree::PageBlocks::Link |
Product Blocks
These blocks are used in the Product Details section:| Block | Description | Class |
|---|---|---|
| Title | Product title | Spree::PageBlocks::Products::Title |
| Price | Product price display | Spree::PageBlocks::Products::Price |
| Description | Product description | Spree::PageBlocks::Products::Description |
| Variant Picker | Size/color selector | Spree::PageBlocks::Products::VariantPicker |
| Quantity Selector | Quantity input | Spree::PageBlocks::Products::QuantitySelector |
| Buy Buttons | Add to cart button | Spree::PageBlocks::Products::BuyButtons |
| Share | Social sharing buttons | Spree::PageBlocks::Products::Share |
Architecture
Base Class
All blocks inherit from Spree::PageBlock:Default Preferences
Every block has these default preferences:| Preference | Type | Default | Description |
|---|---|---|---|
text_alignment | String | left | Text alignment (left, center, right) |
container_alignment | String | left | Container alignment |
size | String | medium | Block size (small, medium, large) |
width_desktop | Integer | 100 | Width percentage on desktop |
top_padding | Integer | 0 | Top padding in pixels |
bottom_padding | Integer | 0 | Bottom padding in pixels |
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:
Key Methods
| Method | Description |
|---|---|
display_name | Name shown in Page Builder sidebar |
icon_name | Icon from Tabler Icons |
form_partial_name | Name of the admin form partial |

