SyliusCon 2025
Early Bird Deal
LogoLogo
🛣️ Roadmap💻 Sylius Demo💬 Community Slack
  • Sylius Documentation
  • Sylius Plugins
  • Sylius Stack
  • Sylius Stack Documentation
  • Getting started
  • Cookbook
    • How to customize your admin panel
      • Basic operations
      • Customizing your grids
      • Customizing the logo
      • Customizing the menu
      • Configuring the security access
      • Customizing the page titles
    • How to use in a DDD architecture
      • Architecture overview
      • Resource configuration
      • Basic operations
      • Operation using a grid
  • Admin UI
    • Getting started
  • Bootstrap Admin UI
    • Getting started
  • Resource
    • Resource Bundle documentation
      • Installation
      • Create new resource
      • Configure your resource
      • Configure your operations
      • Validation
      • Redirect
      • Resource factories
      • Providers
      • Processors
      • Responders
      • Legacy Resource Documentation
        • Configuration
        • Services
        • Routing
        • Forms
        • Getting a Single Resource
        • Getting a Collection of Resources
        • Creating Resources
        • Updating Resources
        • Deleting Resources
        • Configuring a state machine
        • Configuration Reference
  • Grid
    • Grid Bundle documentation
      • Installation
      • Creating your first grid
      • Configuring Fields
      • Field types
      • Creating a custom Field Type
      • Creating a custom Action
      • Creating a custom Bulk Action
      • Filters
      • Creating a custom Filter
      • Advanced configuration
      • Configuration Reference
  • 🍀Twig Extra
    • Getting started
  • 🌱Twig Hooks
    • Getting started
    • Passing data to your hookables
    • Making your hookables configurable
    • Autoprefixing feature
    • Composable Layouts with a predictable structure
    • Advanced
      • Ergonomic work with hooks
      • Metadata objects
      • Multiple hooks inside a single template
      • Overriding hookables
Powered by GitBook
LogoLogo

Developer

  • Community
  • Online Course

About

  • Team

© 2025 Sylius. All Rights Reserved

On this page
  • Installation
  • Features
  • Sort by
  • Test HTML attribute
  • Test Form HTML attribute

Was this helpful?

Edit on GitHub
  1. Twig Extra

Getting started

Twig Extra is a set of Twig extensions that provides additional Twig helpers.

Installation

Install the package using Composer and Symfony Flex:

composer require sylius/twig-extra

Features

Sort by

This extension allows you to sort an array of objects by a specific property.

class Book {
    public function __construct() {
        public string $name,
    }
}

$books = [
    new Book('The Shining'), 
    new Book('The Lord Of The Rings'), 
    new Book('Dune'),
    new Book('Wuthering Heights'),
    new Book('Fahrenheit 451'),
];
<ul>
{% for book in books|sort_by('name') %}
    <li>{{ book.name }}</li>
{% endif %}
</ul>
. Dune
. Fahrenheit 451
. The Lord Of The Rings
. The Shining
. Wuthering Heights

You can also sort nested arrays.


$books = [
    ['name' => 'The Shining'], 
    ['name' => 'The Lord Of The Rings'],
    ['name' => 'Dune'],
    ['name' => 'Wuthering Heights'],
    ['name' => 'Fahrenheit 451'],
];

You just need to encapsulate the key with [].

<ul>
{% for book in books|sort_by('[name]') %}
    <li>{{ book.name }}</li>
{% endif %}
</ul>

Test HTML attribute

This Twig extension lets you add data attributes in a test environment or when debug mode is enabled. This makes it easy to identify your data in E2E tests while minimizing dependency on HTML changes.

<h1 {{ sylius_test_html_attribute('title')>The Shining</h1>
<h1 data-test-title>The Shining</h1>

Test Form HTML attribute

Like the sylius_test_html_attribute Twig extension, this one allows you to add some data attributes in your test environment or when debug mode is enabled. This function adds the data attribute via the attr Twig variable on a form theme block.

{{ form_row(form.title, sylius_test_form_attribute('title')) }}
<!-- Actual html output below depends on your form theme -->
<label for="book_title">Title</label>
<input 
        type="text" 
        id="book_title" 
        name="title" 
        data-test-title <!-- This is the added data attribute -->
/>
PreviousConfiguration ReferenceNextGetting started

Last updated 5 months ago

Was this helpful?

🍀