LogoLogo
sylius.com
  • 📓Sylius 1.x Documentation
  • 📖Sylius 2.0 Documentation
    • Organization
      • Release Cycle
      • Backwards Compatibility Promise
      • Sylius Team
      • Sylius Roadmap
  • Getting Started with Sylius
    • Installation
    • Basic Configuration
    • Shipping & Payment
    • First Product
    • Customizing the Shop
    • Customizing Business Logic
    • Using API
    • Installing Plugins
    • Deployment
    • Summary
  • The Book
    • Introduction to Sylius
    • Installation
      • System Requirements
      • Sylius CE Installation
        • Sylius CE Installation with Docker
      • ➕Sylius Plus Installation
      • Upgrading Sylius CE
      • Upgrading Sylius Plus
    • Architecture
      • Architecture Overview
      • Architectural Drivers
      • Resource Layer
      • State Machine
      • Translations
      • E-Mails
      • Contact
      • Fixtures
      • Events
    • Configuration
      • Channels
      • Locales
      • Currencies
    • Customers
      • Customer & ShopUser
      • ➕Customer Pools
      • AdminUser
      • Addresses
        • Countries
        • Zones
        • Addresses
        • Address Book
    • Products
      • Products
      • Product Reviews
      • Product Associations
      • Attributes
      • Pricing
      • Catalog Promotions
      • Taxons
      • Inventory
      • ➕Multi-Source Inventory
      • Search
    • Carts & Orders
      • Orders
      • Cart flow
      • Taxation
      • Adjustments
      • Cart Promotions
      • Coupons
      • Payments
      • 🧩Invoices
      • Shipments
    • Support
    • Contributing
      • Contributing Code
        • Submitting a Patch
        • ⚠️Security Issues
        • Coding Standards
        • Conventions
        • Sylius License and Trademark
      • Key Contributors
  • The Customization Guide
    • Customizing Models
      • How to add a custom model?
    • Customizing Forms
      • How to add a live form for a custom model?
    • Customizing Templates
    • Customizing Translations
    • Customizing Flashes
    • Customizing API
    • Customizing Serialization of API
    • Customizing Payments
      • How to integrate a Payment Gateway as a Plugin?
  • Sylius Official Plugins Documentation
    • CMS Plugin
      • Getting Started
        • Installation
      • Features Overview
        • Collections
        • Content Templates
        • Pages
        • Blocks
        • Media
      • Developer Reference
        • Collections
        • Pages
        • Blocks
        • Media
        • Content Element
        • Templates
  • THE COOKBOOK v1.x
    • The Cookbook v1.x
Powered by GitBook
LogoLogo

Developer

  • Community
  • Online Course

About

  • Team

© 2024 Sylius. All Rights Reserved

On this page
  • Desing with Twig Hooks
  • Configuration
  • Example configuration
  • Design directly in Twig Template
  • Render the block
  • Context Configuration

Was this helpful?

Edit on GitHub
  1. Sylius Official Plugins Documentation
  2. CMS Plugin
  3. Developer Reference

Blocks

Desing with Twig Hooks

Configuration

Use the sylius_cms.shop:render:block component and pass the following props:

  • code The unique identifier of the collection you want to render.

  • template (optional) Path to a custom Twig template for rendering the block. When you provide your own template, you are responsible for rendering the content.

  • context (optional) Set the limitation for the product,

Example configuration

sylius_twig_hooks:
    hooks:
        'sylius_shop.product.show.content.info.overview.accordion.details':
            dynamic_details:
                component: 'sylius_cms.shop:render:block'
                props:
                    code: 'my_block_code'
                    template: 'my_custom_template.html.twig' # optional
                    context: '@=_context.resource' #optional, see 'Context Configuration' section below

Design directly in Twig Template

Render the block

{{ sylius_cms_render_block('my_block_code') }}

You can render the custom template by passing the appropriate option:

{{ sylius_cms_render_block('my_block_code', 'my_custom_template.html.twig') }}

Context Configuration

The context prop allows you to pass additional variables to the block template. It supports three types: ProductInterface, TaxonInterface, or an array.

{{ sylius_cms_render_block('homepage_intro', null, {'some_variable': 'some_value'}) }}
{{ sylius_cms_render_block('homepage_intro', null, product) }}
{{ sylius_cms_render_block('homepage_intro', null, taxon) }}

When you pass a ProductInterface or TaxonInterface as the context, the block will be rendered only if it is assigned to the corresponding product or taxon in the admin panel.

PreviousPagesNextMedia

Last updated 1 day ago

Was this helpful?