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'),
];

You can also sort nested arrays.

You just need to encapsulate the key with [].

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.

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.

Last updated