ocubom / twig-extra-bundle
A Symfony bundle for custom extra Twig extensions
Package info
github.com/ocubom/twig-extra-bundle
Type:symfony-bundle
pkg:composer/ocubom/twig-extra-bundle
Requires
- php: >=7.4
- symfony/config: ^5.4|^6.0|^7.0|^8.0
- symfony/dependency-injection: ^5.4|^6.0|^7.0|^8.0
- symfony/http-kernel: ^5.4|^6.0|^7.0|^8.0
- symfony/twig-bundle: ^5.4|^6.0|^7.0|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: *
- ocubom/twig-html-extension: ^1.0|^2.0
- ocubom/twig-svg-extension: ^1.0|^2.0
- phpstan/phpstan: ^2.2
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- symfony/phpunit-bridge: ^6.1|^7.0|^8.0
- symfony/webpack-encore-bundle: ^1.16|^2.0
Suggests
- ocubom/twig-html-extension: Allows using Twig HTML extension
- ocubom/twig-svg-extension: Allows using Twig SVG extension
Provides
None
Conflicts
None
Replaces
None
README
A Symfony bundle for custom extra Twig extensions.
Explore the docs » · Report Bug · Request Feature
About ocubom/twig-extra-bundle
ocubom/twig-extra-bundle allows the use of several custom Twig extensions with zero configuration.
This suite started as an internal helper based on nochso/html-compress-twig to bring wyrihaximus/html-compress support to Twig 3.0. Over time, as several projects embedded and modified this class independently, development became fragmented and difficult to maintain. To resolve this, several standalone open-source extensions were created to unify those efforts.
This repository provides a Symfony bundle to easily integrate all those extensions into a Symfony project. The bundle continues to evolve to configure additional custom extensions, following the philosophy of twig/extra-bundle.
Getting Started
Prerequisites
- PHP >= 7.4 (tested up to 8.5)
- Composer >= 2.0
Installation
Install the package via composer:
composer require ocubom/twig-extra-bundle
You must also install the Twig extensions you want to use:
# For HTML filters (`html_attributes`, `html_minify`) composer require ocubom/twig-html-extension # For SVG filters (`svg`, `svg_symbols`, `fontawesome`, `iconify`) composer require ocubom/twig-svg-extension
Optional Dependencies
You can install additional packages to plug extra functionality:
- For HTML minification (ocubom/twig-html-extension):
composer require matthiasmullie/minify ## scripts & styles composer require wikimedia/minify ## scripts & styles composer require tedivm/jshrink ## scripts only composer require tubalmartin/cssmin ## styles only
- For SVG sanitization (ocubom/twig-svg-extension):
composer require enshrined/svg-sanitize
Usage
Enable the bundle by adding it to the list of registered bundles in the
config/bundles.php file of your project:
// config/bundles.php return [ // ... Ocubom\TwigExtraBundle\OcubomTwigExtraBundle::class => ['all' => true], ];
Just create the file config/packages/ocubom_twig_extra.yaml using the configuration reference:
bin/console config:dump-reference ocubom_twig_extra
Or you can use the example configuration provided.
Note
This configuration will be installed if your project uses endroid/installer
Roadmap
See the open issues for a list of proposed features (and known issues).
Support
Reach out to the maintainer at GitHub Issues.
Authorship
Oscar Cubo Medina — https://ocubom.github.io
For a full list of all authors and contributors, see the contributors page.
License
Distributed under the MIT License.
See LICENSE for more information.