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

Ux Twig Component Laravel Package

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.

View on GitHub
Deep Wiki
Context7
Pre-Release
  • The TwigComponent library was introduced!
3.1.0
  • Add provide() and inject() Twig functions to share state from a parent component down to deeply-nested descendants without prop drilling
3.0.0
  • Minimum required Symfony version is now 7.4
  • Minimum required PHP version is now 8.4
  • The configuration twig_component.defaults could not be nullable anymore
  • Remove method PreCreateForRenderEvent::getProps() in favor of PreCreateForRenderEvent::getInputProps()
  • Remove cva Twig function in favor of html_cva Twig function from twig/html-extra
  • Passing null as an attribute value when using ComponentAttributes (or attributes Twig variable) will now throw an exception, use remove() instead
  • Remove method ComponentAttributes::add(), use {{ attributes.defaults(stimulus_controller('...')) }} instead
  • The ComponentTemplateFinder does not accept Twig\Environment as first argument anymore, pass a LoaderInterface instead
  • The ComponentTemplateFinder does not accept a nullable directory argument anymore, pass a string instead
  • Remove old compatibility layer with deprecated StimulusTwigExtension from WebpackEncoreBundle ^1.0, use StimulusBundle instead
2.9.0
  • The ComponentAttributes::defaults() method now accepts any iterable argument. The ComponentAttributes::add() method has been deprecated. To add a Stimulus controller to the attributes, use {{ attributes.defaults(stimulus_controller('...')) }}.
2.8.0
  • Add new HTML syntax for rendering components: <twig:ComponentName>
  • true attribute values now render just the attribute name, false excludes it entirely.
  • Add helpers for testing components.
  • The first argument to AsTwigComponent is now optional and defaults to the class name.
  • Allow passing a FQCN to ComponentFactory methods.
2.7.0
  • PreMount and PostMount hooks can now return nothing.
2.5
  • [BC BREAK] The PreRenderEvent namespace was changed from Symfony\UX\TwigComponent\EventListener to Symfony\UX\TwigComponent\Event.

  • Add new autowireable ComponentRendererInterface

  • Added PostRenderEvent and PreCreateForRenderEvent which are dispatched just before or after a component is rendered.

  • Added PostMountEvent and PreMountEvent which are dispatched just before or after the component's data is mounted.

  • Added Twig template namespaces - #460.

2.35
  • Add support for AttributeValueInterface from twig/html-extra:^3.24.0 in ComponentAttributes
  • Allow Symfony UX 3.x packages
2.33
  • Extended support for the index.html.twig template fallback when resolving namespaced anonymous components
  • Add support for dynamic template resolution with AsTwigComponent(template: FromMethod('getCustomFuntion'))
2.32
  • Add option profiler.collect_components to control component data collection in the profiler (enabled in debug mode by default)
  • Add support for using directory name as component name for anonymous components
2.30
  • Ensure compatibility with PHP 8.5
2.29.0
  • Add Symfony 8 support
2.25.2
  • Fix ComponentAttributes rendering when using StimulusAttributes as default attributes
2.25.1
  • [SECURITY] ComponentAttributes now requires a Twig\Runtime\EscaperRuntime instance as second argument
  • Remove HtmlAttributeEscaperInterface, TwigHtmlAttributeEscaper and ComponentAttributesFactory
2.25.0
  • [SECURITY] Make ComponentAttributes responsible for attribute escaping ensuring consistent and secure HTML output across all rendering contexts
  • Deprecate not passing an HtmlAttributeEscaperInterface to the ComponentAttributes constructor
2.20.0
2.2
  • Allow to pass stringable object as non mapped component attribute.
  • Add embedded components.
  • Allow ExposeInTemplate to be used on public component methods.
2.17.0
  • Add nested attribute support #1405
2.16.0
  • Introduce CVA to style TwigComponent #1416
  • Drop Twig 2 support #1436
  • Fix full context is stored in profiler #1552
  • Add CVA (Class variant authority) integration #1416
2.15.0
  • Add the ability to render specific attributes from the attributes variable #1442
  • Restrict Twig 3.9 for now #1486
  • Build reproducible TemplateMap to fix possible post-deploy breakage #1497
2.14.0
  • Make ComponentAttributes traversable/countable
  • Fixed lexing some {# twig comments #} with HTML Twig syntax
  • Fix various usages of deprecated Twig code
2.13.0
  • [BC BREAK] Add component metadata to PreMountEvent and PostMountEvent
  • Added configuration to separate your components into different "namespaces"
  • Add outerScope variable reach variables from the parent template of an "embedded" component.
  • Deprecate calling ComponentTemplateFinder constructor without directory argument.
  • Add profiler integration: TwigComponentDataCollector and debug toolbar templates
  • Add search feature in debug:twig-component command.
  • Fix inconsistencies with how {% component %}/<twig:component> syntaxes are rendered vs component(): PostRenderEvent is now dispatched & the template resolution happens at runtime.
  • Fix priority of passed in props vs default props with anonymous components.
  • Add Symfony 7 support.
  • TwigPreLexer: improve performance.
  • Fix twig:lint bug with anonymous component tag.
2.12.0
  • Added a debug:twig-component command.
  • Fixed bad exception when the error comes from a Twig template.
  • Fixed deprecation with TemplateCacheWarmer return type.
2.11.0
  • Support ...spread operator with html syntax (requires Twig 3.7.0 or higher)
  • Add support for anonymous Twig components.
  • Add RenderedComponent::crawler() and toString() methods.
  • Allow a block outside a Twig component to be available inside via outerBlocks.
  • Fix <twig:component> syntax where an attribute is set to an empty value.
  • Add component debug command for TwigComponent and LiveComponent.
2.1
  • Make public component properties available directly in the template ({{ prop }} vs {{ this.prop }}).

  • Add PreMount priority parameter.

  • Add PostMount hook component hook to intercept extra props.

  • Add attributes system that takes extra props passed to component() and converts them into a ComponentAttributes object available in your template as attributes.

  • Add PreRenderEvent to intercept/manipulate twig template/variables before rendering.

  • Add ExposeInTemplate attribute to make non-public properties available in component templates directly.

  • Add Computed Properties system.

2.0.0
  • Support for stimulus version 2 was removed and support for [@hotwired](https://github.com/hotwired)/stimulus version 3 was added. See the [@symfony/stimulus-bridge CHANGELOG](https://github.com/symfony/stimulus-bridge/blob/main/CHANGELOG.md#300) for more details.

  • Minimum PHP version was bumped to 8.0 so that PHP 8 attributes could be used.

  • The ComponentInterface was dropped and replaced by the AsTwigComponent attribute. The getComponentName() was replaced by a name argument to the attribute.

Before:

use Symfony\UX\TwigComponent\ComponentInterface;

class AlertComponent implements ComponentInterface
{
    public string $type = 'success';
    public string $message;

    public static function getComponentName(): string
    {
        return 'alert';
    }
}

After:

use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent('alert')]
class AlertComponent
{
    public string $type = 'success';
    public string $message;
}
  • If you're using a version lower than Symfony 5.3, you will need to manually tag all component services with twig.component. This is because Symfony 5.3 introduces autoconfiguration for PHP 8 attributes, which this library leverages.

  • The template for a component can now be controlled via the template argument to the AsTwigComponent attribute:

use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent('alert', template: 'other/path/alert.html.twig')]
class AlertComponent
{
    // ...
}
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai