symfony/twig-bridge
Symfony’s Twig Bridge integrates the Twig templating engine with Symfony components, providing extensions, loaders, form and translation support, and other glue code needed to use Twig seamlessly in Symfony-based applications.
TwigBridge, FormThemeNode, and EscaperRuntime are decoupled, allowing selective adoption (e.g., use Twig for emails without full frontend integration).symfony/http-foundation or symfony/mailer).TwigBundle). Laravel’s native blade templating may conflict with Twig’s syntax.twig-bridge may require updates to:
3.25+ for EscaperRuntime).phpdocumentor/reflection-docblock conflicts in v8.0+).CodeExtension::fileExcerpt() in v8.0.12), but audit custom Twig extensions for similar issues.symfony/polyfill) may introduce conflicts.@extends, @section).symfony/http-foundation for Response objects).composer require twig/twig symfony/twig-bridge
config/app.php:
'twig' => [
'paths' => [base_path('resources/views')],
'options' => [
'debug' => env('APP_DEBUG'),
'auto_reload' => env('APP_DEBUG'),
],
],
AssetMapper for versioned asset URLs if using Symfony’s Uris.@if, @foreach) do not translate 1:1 to Twig ({% if %}, {% for %}). Requires template rewrites.{{ form_row(form) }} syntax; Laravel’s Form helpers won’t work.access_decision(); replace Laravel’s auth() checks.TemplatedEmail.Router won’t integrate natively; use Laravel’s router for URLs.| Phase | Task | Tools/Dependencies |
|---|---|---|
| Preparation | Audit templates, identify Symfony dependencies. | composer why symfony/twig-bridge |
| Core Integration | Install Twig, configure loader, test basic templates. | twig/twig, symfony/twig-bridge |
| Feature Migration | Replace Blade forms/security with Twig Bridge equivalents. | Symfony’s FormTheme, SecurityBundle |
| Asset Handling | Migrate from Laravel Mix to Symfony’s AssetMapper (optional). |
symfony/asset |
| Testing | Validate Twig templates in CI, check for XSS/performance regressions. | PHPUnit, Pest |
| Rollout | Deploy Twig for non-critical paths first (e.g., emails). | Feature flags, canary releases |
symfony/twig-bridge to a specific minor version (e.g., 8.0.x) to avoid breaking changes.EscaperRuntime).twig:lint and Symfony’s debug:twig for template validation.twig.twig language mode).fileExcerpt() usage post-upgrade.symfony/twig-bridge to Dependabot/Snyk alerts.symfony/web-profiler-bundle for Twig template debugging (if integrated).{{ dump() }} or var_dump().How can I help you explore Laravel packages today?