Weave 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
Ux Twig Component

Ux Twig Component Laravel Package

symfony/ux-twig-component

Twig Components let you bind a PHP object to a Twig template, turning small reusable units like alerts, modals, or sidebars into clean, self-contained components you can render anywhere in your Symfony app.

View on GitHub
Deep Wiki
Context7

Twig components for Symfony

Frequently asked questions about Ux Twig Component
Does symfony/ux-twig-component work with Laravel?
No. It is built for Symfony and Twig, not Laravel's Blade templating engine. Laravel developers can use it only inside a Symfony application or treat it as a conceptual comparison to Blade components.
How do I install symfony/ux-twig-component?
Install it with Composer using composer require symfony/ux-twig-component. In a Symfony app, enable the bundle if Flex does not do it automatically, then configure twig_component under twig in config/packages/twig.yaml. Current v3 requirements include Symfony 7.4+ and PHP 8.4+.
What Symfony and PHP versions does symfony/ux-twig-component require?
The current v3 line requires Symfony 7.4+ and PHP 8.4+, plus Twig 3.9+ for HTML component syntax and spread operator support. Older Symfony or PHP versions need an upgrade path before adopting v3. Always check the package constraints for exact compatibility.
How do I create a Twig component with #[AsTwigComponent]?
Create a PHP class, annotate it with #[AsTwigComponent], and pair it with a Twig template. The class can define public properties as props and use lifecycle hooks for setup. Render it in Twig using the component function or HTML syntax like <twig:Alert type="error" />.
Can I use Twig components without Stimulus?
Yes. Static components such as alerts, cards, and sidebars work without Stimulus. Stimulus is optional and only needed for interactivity like modals, collapsible panels, or live updates. You can adopt static components first and add Stimulus later.
How do I test Twig components in Symfony?
Use Symfony's test tools and the built-in RenderedComponent::crawler() to inspect rendered component markup. Render components in a test case and assert on the resulting HTML or crawler output. This lets you test props, lifecycle behavior, and template output without a browser.
How do I debug Twig components in Symfony?
Use the debug:twig-component command and Symfony profiler integration to inspect component resolution and rendering. Component props and state can be opaque without these tools, so enable profiler support in dev. This helps trace runtime template resolution and nested component issues.
What are alternatives to symfony/ux-twig-component for reusable UI in Symfony?
Traditional Twig includes, embeds, and macros remain alternatives for simple reuse. Symfony UX Twig Components adds PHP-backed props, lifecycle hooks, and provide/inject for more structured components. For Laravel, the closest comparison is Blade components.
Is symfony/ux-twig-component production ready and maintained?
Yes, it is part of Symfony UX and maintained in the main Symfony UX repository. It is backed by Symfony's release process and Mercure.rocks sponsorship. Review upgrade notes because v3 introduced breaking changes and stricter version requirements.
How do I migrate existing Twig includes to Twig components?
Audit templates for reusable units like alerts, cards, forms, and modals, then pilot high-impact components. Start by replacing static includes with #[AsTwigComponent] classes and templates, then add props, attributes, and optionally Stimulus interactivity. Adopt incrementally so components and includes can coexist during migration.
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.
laravel2580/idehelpers
delatbabel/viewpages
anavel/gettext
muhamadrezaar/highcharts
delatbabel/keylists
frankkessler/salesforce-laravel-oauth2-rest
anavel/foundation
wdmtech/enviricons
eii/laravel-captcha
muka/shape-reader
tdt/json
refinery29/php-cs-fixer-config
hotmeteor/eco-env
mvaliolahi/hydrate
wearede/tbcpay-php
parsnick/steak
thibaud-dauce/mattermost-php
multilinguals/apollo-client
antaresbr/collection
kr0lik/phpstan-rules