Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Twig Extensions

Twig Extensions Laravel Package

sonata-project/twig-extensions

Provides a set of useful Twig extensions for Sonata projects, adding extra filters, functions, and helpers to enhance templates. Install via Composer and integrate with Twig to simplify common view tasks and formatting.

View on GitHub
Deep Wiki
Context7

Sonata twig extensions

Frequently asked questions about Twig Extensions
Does sonata-project/twig-extensions work with Laravel 11.x?
Yes, but only if your Laravel 11.x project uses PHP 8.2+. Laravel 11.x itself supports PHP 8.2+, so compatibility is maintained. Ensure your `composer.json` enforces PHP 8.2+ and audit Symfony dependency conflicts.
Can I use this package with Laravel 10.x?
Laravel 10.x *can* work with PHP 8.2+, but not all addons or Laravel 10.x installations default to PHP 8.2. Test thoroughly for Symfony 8.x conflicts, especially with `symfony/http-foundation` or `symfony/options-resolver`. Upgrade PHP if needed.
What happens if I’m stuck on PHP 8.1?
This package **requires PHP 8.2+**, so PHP 8.1 users cannot use it. Consider alternatives like Blade templating, Alpine.js, or Livewire for dynamic UI components. Upgrade PHP if possible, or skip this package.
How do I install sonata-project/twig-extensions in Laravel?
Run `composer require twig/laravel sonata-project/twig-extensions:^2.6`. Then configure Twig in `config/view.php` by setting `'enabled' => true` for Twig. Ensure your `composer.json` enforces PHP 8.2+ with `"config": { "platform": { "php": "8.2.0" } }`.
Will this package conflict with Laravel’s built-in Symfony components?
Possible, especially with Symfony 8.x dependencies like `symfony/string` or `symfony/options-resolver`. Run `composer why symfony/http-foundation` to check for conflicts. Laravel 11.x may mitigate this, but test in a staging environment first.
What Twig extensions does this package provide for Laravel?
Sonata’s package includes filters (e.g., `sonata_block`), functions for dynamic UI components, and helpers for legacy Symfony/Sonata migrations. It’s ideal for complex templates but less critical for minimalist SPAs or headless APIs.
How do I migrate from Blade to Twig with Sonata’s extensions?
First, install `twig/laravel` and `sonata-project/twig-extensions`. Then incrementally replace Blade templates with Twig. Use hybrid Blade/Twig where needed, but note Sonata’s extensions are Twig-specific. Test thoroughly for edge cases.
Are there alternatives to Sonata’s Twig extensions for Laravel?
For Blade users, consider Livewire or Alpine.js for dynamic components. For Twig, alternatives include `twiglabs/twig-extras` or custom filters. If avoiding PHP 8.2, stick to Blade or frontend frameworks like Vue/React for templating.
How do I handle Symfony 8.x API changes (e.g., Stringable interface) in Laravel?
Override Sonata’s `BlockService` or related classes to adapt to Symfony 8.x changes. Laravel 11.x may already include compatible Symfony components, but test for conflicts. Check Sonata’s docs for migration guides specific to Symfony 8.x.
Is this package production-ready for Laravel 11.x?
Yes, but verify PHP 8.2+ compatibility and Symfony dependency conflicts. Test in staging with your full stack, including caching (Twig’s runtime parsing may impact performance). Monitor for Twig error handling quirks in Laravel’s exception system.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
directorytree/privacy-filter-classifier
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi