- Fix the pre-lexer mistaking a
<twig:written inside a{% %}tag for a component (for example in the## ...documentation of a prop, in a#inline comment or in a string)
- Render component attributes through twig/html-extra's
html_attr(), so a component and a plain Twig template render attributes identically. It may break your tests if you assert on the rendered HTML of a component's attributes, since boolean,null,aria-*and non-scalar values now render differently. Re-generate those assertions after upgrading.nullnow omits the attribute instead of throwingtruerenders asname=""; fordata-*andaria-*attributes it rendersname="true"falseomits the attribute, exceptaria-*which now rendersname="false"instead of being dropped- Arrays, iterables and
BackedEnumvalues are now supported attributes.render()follows the same rules and returnsnullfor an omitted attribute instead of throwing on a non-string value- Requires
twig/html-extra^3.29andtwig/twig^3.24
- Add support for
MergeableInterfacefromtwig/html-extrainComponentAttributes#defaults() - Add support for dynamic component names in the HTML syntax using
<twig:component is="myComponent" ... - Capture
## <description>documentation comments written above props inside{% props %}(Twig 3.29+), exposed per prop viaPropsNode::getPropDocumentation() - Fix
{% props %}treating a prop explicitly passed asnullas missing: a required prop no longer throws, and a prop declaring a default value now keeps thenullit was given - Fix the pre-lexer treating a
{#inside a{{ ... }}expression as the start of a Twig comment, which silently stopped every component after it from being rendered - Fix HTML/
{% component %}syntax failing when a prop uses the null-safe operator (?.) - Add support for Twig 4
- Add support for dynamic component names in the
{% component %}tag using a parenthesized expression, e.g.{% component (prefix ~ i) %}{% endcomponent %}
- Add
ComponentRendererInterface::preCreateForRender(),ComponentRendererInterface::startEmbeddedComponentRender(), andComponentRendererInterface::finishEmbeddedComponentRender()methods - Allow using
ComponentFactoryandComponentRuntimewith any PSR-11 container, makingsymfony/dependency-injectionoptional for standalone usage
- Add
provide()andinject()Twig functions to share state from a parent component down to deeply-nested descendants without prop drilling - Include the attribute name in the error message thrown when an attribute value is
null
- Minimum required Symfony version is now 7.4
- Minimum required PHP version is now 8.4
- The configuration
twig_component.defaultscould not be nullable anymore - Remove method
PreCreateForRenderEvent::getProps()in favor ofPreCreateForRenderEvent::getInputProps() - Remove
cvaTwig function in favor ofhtml_cvaTwig function fromtwig/html-extra - Passing
nullas an attribute value when usingComponentAttributes(orattributesTwig variable) will now throw an exception, useremove()instead - Remove method
ComponentAttributes::add(), use{{ attributes.defaults(stimulus_controller('...')) }}instead - The
ComponentTemplateFinderdoes not acceptTwig\Environmentas first argument anymore, pass aLoaderInterfaceinstead - The
ComponentTemplateFinderdoes not accept a nullabledirectoryargument anymore, pass a string instead - Remove old compatibility layer with deprecated
StimulusTwigExtensionfrom WebpackEncoreBundle ^1.0, use StimulusBundle instead
- Add support for
AttributeValueInterfacefromtwig/html-extra:^3.24.0inComponentAttributes - Allow Symfony UX 3.x packages
- Extended support for the
index.html.twigtemplate fallback when resolving namespaced anonymous components - Add support for dynamic template resolution with
AsTwigComponent(template: FromMethod('getCustomFuntion'))
- Add option
profiler.collect_componentsto 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
- Ensure compatibility with PHP 8.5
- Add Symfony 8 support
- Fix
ComponentAttributesrendering when usingStimulusAttributesas default attributes
- [SECURITY]
ComponentAttributesnow requires aTwig\Runtime\EscaperRuntimeinstance as second argument - Remove
HtmlAttributeEscaperInterface,TwigHtmlAttributeEscaperandComponentAttributesFactory
- [SECURITY] Make
ComponentAttributesresponsible for attribute escaping ensuring consistent and secure HTML output across all rendering contexts - Deprecate not passing an
HtmlAttributeEscaperInterfaceto theComponentAttributesconstructor
- Add Anonymous Component support for 3rd-party bundles #2019
- Deprecate
cvaTwig function in favor ofhtml_cvafromtwig/html-extra#2144
- Add nested attribute support #1405
- 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
- Add the ability to render specific attributes from the
attributesvariable #1442 - Restrict Twig 3.9 for now #1486
- Build reproducible TemplateMap to fix possible post-deploy breakage #1497
- Make
ComponentAttributestraversable/countable - Fixed lexing some
{# twig comments #}with HTML Twig syntax - Fix various usages of deprecated Twig code
- [BC BREAK] Add component metadata to
PreMountEventandPostMountEvent - Added configuration to separate your components into different "namespaces"
- Add
outerScopevariable reach variables from the parent template of an "embedded" component. - Deprecate calling
ComponentTemplateFinderconstructor withoutdirectoryargument. - Add profiler integration:
TwigComponentDataCollectorand debug toolbar templates - Add search feature in
debug:twig-componentcommand. - Fix inconsistencies with how
{% component %}/<twig:component>syntaxes are rendered vscomponent():PostRenderEventis 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.
- Added a
debug:twig-componentcommand. - Fixed bad exception when the error comes from a Twig template.
- Fixed deprecation with
TemplateCacheWarmerreturn type.
- Support ...spread operator with html syntax (requires Twig 3.7.0 or higher)
- Add support for anonymous Twig components.
- Add
RenderedComponent::crawler()andtoString()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.
- The
ComponentAttributes::defaults()method now accepts any iterable argument. TheComponentAttributes::add()method has been deprecated. To add a Stimulus controller to the attributes, use{{ attributes.defaults(stimulus_controller('...')) }}.
- Add new HTML syntax for rendering components:
<twig:ComponentName> trueattribute values now render just the attribute name,falseexcludes it entirely.- Add helpers for testing components.
- The first argument to
AsTwigComponentis now optional and defaults to the class name. - Allow passing a FQCN to
ComponentFactorymethods.
PreMountandPostMounthooks can now return nothing.
-
[BC BREAK] The
PreRenderEventnamespace was changed fromSymfony\UX\TwigComponent\EventListenertoSymfony\UX\TwigComponent\Event. -
Add new autowireable
ComponentRendererInterface -
Added
PostRenderEventandPreCreateForRenderEventwhich are dispatched just before or after a component is rendered. -
Added
PostMountEventandPreMountEventwhich are dispatched just before or after the component's data is mounted. -
Added Twig template namespaces - #460.
- Allow to pass stringable object as non mapped component attribute.
- Add embedded components.
- Allow
ExposeInTemplateto be used on public component methods.
-
Make public component properties available directly in the template (
{{ prop }}vs{{ this.prop }}). -
Add
PreMountpriority parameter. -
Add
PostMounthook component hook to intercept extra props. -
Add attributes system that takes extra props passed to
component()and converts them into aComponentAttributesobject available in your template asattributes. -
Add
PreRenderEventto intercept/manipulate twig template/variables before rendering. -
Add
ExposeInTemplateattribute to make non-public properties available in component templates directly. -
Add Computed Properties system.
-
Support for
stimulusversion 2 was removed and support for@hotwired/stimulusversion 3 was added. See the @symfony/stimulus-bridge CHANGELOG for more details. -
Minimum PHP version was bumped to 8.0 so that PHP 8 attributes could be used.
-
The
ComponentInterfacewas dropped and replaced by theAsTwigComponentattribute. ThegetComponentName()was replaced by anameargument 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
templateargument to theAsTwigComponentattribute:
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
#[AsTwigComponent('alert', template: 'other/path/alert.html.twig')]
class AlertComponent
{
// ...
}- The TwigComponent library was introduced!