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
  • Design with Twig Hooks
  • Example:
  • Design directly in Twig Template
  • Miscellaneous

Was this helpful?

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

Collections

Design with Twig Hooks

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

  • code (string, required) The unique identifier of the collection you want to render.

  • count_to_render (int, optional) Limits the number of items displayed:

    • If count_to_render ≤ 0, all items in the collection will be rendered.

    • If count_to_render exceeds the total number of items, all items will be rendered.

    • Otherwise, only the specified number of items will be rendered.

  • template (string, optional) Path to a custom Twig template for rendering the collection. When you provide your own template, you are responsible for rendering the collection items inside it. For example, your template might look like this:

    {# templates/collection/custom.html.twig #}
    <div>
      {{ content|raw }}
    </div>
    

Example:

sylius_twig_hooks:
    hooks:
        'sylius_shop.product.show.content.info.overview.accordion.details':
            dynamic_details:
                component: 'sylius_cms.shop:render:collection'
                props:
                    code: 'some_collection_code'
                    count_to_render: 1
                    template: 'collection/custom.html.twig'

Design directly in Twig Template

Just call the predefined Twig function:

{{ sylius_cms_render_collection('some_collection_code') }}

You can also customize how many items are rendered and use your own template:

{{ sylius_cms_render_collection(
    'some_collection_code', 
    3,
    'collection/custom.html.twig'
) }}

Miscellaneous

By default, collection items are sorted by their object ID. To change this behavior, you can use a decorator strategy.

PreviousDeveloper ReferenceNextPages

Last updated 2 days ago

Was this helpful?

Learn more about it .

here