symfony/ux-twig-component
Symfony UX Twig Components lets you bind PHP objects to Twig templates to build reusable UI pieces like alerts, modals, and sidebars. Create small, composable components with clean rendering and better template organization for Symfony apps.
provide()/inject() for dependency injection across nested components, mitigating prop drilling in complex UIs.@symfony/stimulus-bridge for interactive components, but Stimulus is optional for static components.ComponentInterface). Migration effort depends on existing component base.#[AsTwigComponent], ExposeInTemplate, lifecycle hooks) and Twig’s HTML syntax (<twig:ComponentName>).debug:twig-component command or profiler integration.RenderedComponent::crawler() for component testing?<twig:ComponentName>) and spread operator support.AttributeValueInterface and performance optimizations.#[AsTwigComponent] (e.g., alert.html.twig → AlertComponent).{{ component('alert', { type: 'error', message: '...' }) }}).provide/inject).twig_component in config/packages/twig.yaml:
twig:
twig_component:
default_namespace: App\Component
namespaces:
admin: '%kernel.project_dir%/templates/admin/components'
framework:
profiler:
collect_components: true
RenderedComponent::crawler() for component-specific tests.debug:twig-component to inspect registered components.{% embed %} or {% include %}, but gradual migration is recommended.provide/inject for deeply nested components to avoid prop drilling.AlertComponent) propagate automatically across all usages.ComponentAttributes escaping fixes).debug:twig-component command lists all registered components and their props.README provide clear examples for common use cases (e.g., alerts, modals).<twig:ComponentName>, {% component %}).#[AsTwigComponent]).cache:clear).profiler.collect_components: false in production.AlertComponent while backend owns business logic).admin:dashboard/Component) support multi-team workflows.| Risk | Mitigation |
|---|---|
| Component Registration Errors | Use debug:twig-component to validate all components are discoverable. |
| Prop/State Mismanagement | Leverage ExposeInTemplate and PostMountEvent for validation. |
| Stimulus Integration Issues | Test interactivity in isolation; use stimulus_controller() in attributes. |
| Template Resolution Failures | Ensure ComponentTemplateFinder paths are correct; use index.html.twig fallbacks. |
| Performance Bottlenecks | Profile with Symfony’s profiler; cache templates aggressively. |
| Upgrade Blockers | Test v3.x components against Symfony 7.4+ early; use composer why-not for dependency conflicts. |
RenderedComponent::crawler()).#[AsTwigComponent], props, hooks).How can I help you explore Laravel packages today?