How Links Work
TheSpree::PageLink model provides a flexible way to link to various content types:
- Internal pages - Link to Pages, Products, Taxons, Posts
- External URLs - Link to any external website
- Special links - Email (
mailto:) and phone (tel:) links
Link Model
The Spree::PageLink model has these key attributes:| Attribute | Type | Description |
|---|---|---|
label | String | Display text for the link |
url | String | Custom URL (for external links) |
linkable | Polymorphic | Reference to internal content (Page, Product, etc.) |
parent | Polymorphic | Section or Block the link belongs to |
open_in_new_tab | Boolean | Whether to open in new browser tab |
position | Integer | Order when multiple links exist |
Linkable Types
Links can point to various Spree models:| Linkable Type | Description |
|---|---|
Spree::Page | Internal pages (Home, Shop All, Custom pages) |
Spree::Product | Product detail pages |
Spree::Taxon | Category/collection pages |
Spree::Post | Blog posts |
| Custom URL | Any external or internal URL |
Using Links in Sections
Single Link
For sections that need one link (like a banner):app/models/spree/page_sections/promo_banner.rb
Multiple Links
For sections that need multiple links (like navigation):app/models/spree/page_sections/footer.rb
Using Links in Blocks
Blocks can also have links. Use theSpree::HasOneLink concern for single links:
app/models/spree/page_blocks/cta_button.rb
Accessing Links
Rendering Links
Using the Helper
Thepage_builder_link_to helper renders links with Page Builder support:
Manual Link Rendering
For more control, you can render links manually:Rendering Multiple Links
Admin Form for Links
In your section’s admin form, render the link editor:Single Link
app/views/spree/admin/page_sections/forms/_promo_banner.html.erb
Link URL Resolution
Thelinkable_url method returns the appropriate URL:
Creating Links Programmatically
Automatic Label Setting
When a link’slinkable is set, the label is automatically populated from the linked resource:
linkable.titlelinkable.display_namelinkable.name

