8.4 Shop: Template Migration
This step converts shop templates from Semantic UI to Bootstrap 5 and integrates them with Sylius 2.0 Twig Hooks system.
When to skip this step:
Your plugin has no shop templates
Templates are already using Bootstrap 5 and Twig Hooks
When to do this step:
You have shop pages using Semantic UI
You want to make shop templates customizable in end application
π Overview & Approach
Shop templates are simpler than admin forms:
Usually custom pages (product list, resource details, etc.)
No forms or Live Components (typically)
Focus on content presentation
Two Approaches:
A. Extend Existing Sylius Hooks (for adding content to existing pages)
Add your content to checkout, cart, product pages, etc.
Use existing Sylius hook structure
Example: Add custom checkbox to checkout
B. Custom Hooks for Custom Pages (RECOMMENDED for new pages)
Create your own hook hierarchy
Full control over structure
End application can customize everything
Example: Resource show page, custom product listing
β
RECOMMENDED: Custom Hooks for Custom Pages
Use this when creating new pages in your plugin (like resource detail page, custom listings, etc.).
Hook Naming Convention
Critical principle: Each template file runs ONE hook, and that hook is named after the file.
Pattern:
show.html.twigruns hookplugin.shop.{page}.showcontent.html.twigruns hookcontent(relative) orplugin.shop.{page}.{action}.content(absolute)Hook name = file location pattern
Relative vs Absolute Hook Names:
Relative:
{% hook 'content' %}- automatically resolves based on parent hook contextAbsolute:
{% hook 'plugin.shop.terms.show.content' %}- explicit full pathRecommended: Use relative names for cleaner, more maintainable code
Example hierarchy:
YAML configuration defines hookables (child templates), not the hooks called in templates.
1. Create main page template
templates/shop/resource/show.html.twig:
Key points:
Extend Sylius base layout
Use
{% hook %}tag to make content customizablePass variables needed by sub-templates
2. Create hook configuration
config/twig_hooks/shop/resource/show.yaml:
Hook naming convention:
plugin.shop.{page}.{action}- top levelplugin.shop.{page}.{action}.{section}- sectionsUse priorities to control order (higher = first)
3. Create section templates
templates/shop/resource/show/content.html.twig:
Note on hook names:
Use relative hook names:
{% hook 'content' %}automatically resolves toplugin.shop.resource.show.contentin this contextAlternatively use absolute names:
{% hook 'plugin.shop.resource.show.content' %}The hookables (
header,main, etc.) are defined in YAML and rendered automatically by this hook
templates/shop/resource/show/content/header.html.twig:
templates/shop/resource/show/content/main.html.twig:
Key points:
Access variables via
hookable_metadata.context.{variable}Use Bootstrap 5 classes:
container,row,col-*,cardEach section in separate template = customizable
templates/shop/resource/show/content/breadcrumbs.html.twig (optional but recommended):
Important: Use Sylius breadcrumbs macro (@SyliusShop/shared/breadcrumbs.html.twig) instead of writing HTML manually. This ensures consistent styling with Sylius shop and makes breadcrumbs automatically responsive.
4. Import Twig Hooks config
5. Validate
π Alternative: Extend Existing Sylius Hooks
Use this to add content to existing Sylius pages (checkout, cart, product, etc.).
1. Find existing Sylius hooks
Option A: Symfony Profiler (recommended)
Open the page in browser
Open Symfony Profiler β Twig Hooks tab
See all available hooks
Option B: Grep vendor files
2. Create hook configuration
config/twig_hooks/shop/checkout/complete.yaml:
3. Create template
templates/shop/checkout/complete/content/form/custom.html.twig:
When to use this:
Adding fields to existing forms
Injecting content into existing pages
Extending without replacing
When NOT to use this:
Creating new pages β Use custom hooks
Need full control β Use custom hooks
π¨ Bootstrap 5 Migration
Sylius 2.0 uses Bootstrap 5 instead of Semantic UI. Use standard Bootstrap classes in your templates.
Common patterns:
Container:
container,container-fluidGrid:
row,col-*Cards:
card,card-header,card-bodyButtons:
btn btn-primary
π Finding Existing Sylius Hooks
For developers (manual):
Open shop page in browser
Open Symfony Profiler β Twig Hooks tab
See all available hooks with their structure
Copy hook name and use in your config
For AI:
β
Summary
Recommended approach for shop:
Custom pages: Use custom hooks (full control)
Extending existing pages: Extend Sylius hooks (minimal changes)
Bootstrap 5: Use modern classes
No Live Components needed: Shop is usually static content
Key principles:
Custom hooks for new pages = maximum flexibility
Extend Sylius hooks for small additions
Bootstrap 5:
container,row,col-*,cardclassesPass all needed variables through hook context
Each section = separate template = customizable
What end applications can do:
Disable any section
Reorder sections
Override templates
Add new sections
Change priorities
Last updated
Was this helpful?
