vardumper / html5-twig-component-bundle
Symfony UX Twig Components for typesafe HTML5 elements with ARIA support & enum validation
Fund package maintenance!
vardumper
Buy Me A Coffee
paypal.me/vardumper
Installs: 28
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Type:symfony-bundle
pkg:composer/vardumper/html5-twig-component-bundle
Requires
- php: ^8.4
- symfony/options-resolver: ^5.4|^6.0|^7.0|^8.0
- symfony/twig-bundle: ^5.4|^6.0|^7.0|^8.0
- symfony/ux-twig-component: ^2.0
- vardumper/extended-htmldocument: ^0.2
- dev-main
- 0.2.77
- 0.2.76
- 0.2.75
- 0.2.74
- 0.2.73
- 0.2.72
- 0.2.71
- 0.2.70
- 0.2.68
- 0.2.67
- 0.2.66
- 0.2.65
- 0.2.64
- 0.2.63
- 0.2.62
- 0.2.61
- 0.2.60
- 0.2.59
- 0.2.58
- 0.2.57
- 0.2.56
- 0.2.55
- 0.2.54
- 0.2.53
- 0.2.52
- 0.2.51
- 0.2.50
- 0.2.49
- 0.2.48
- 0.2.47
- 0.2.46
- 0.2.45
- 0.2.44
- 0.2.43
- 0.2.42
- 0.2.41
- 0.2.40
- 0.2.39
- 0.2.38
- 0.2.37
- 0.2.36
- 0.2.35
- 0.2.34
- 0.2.33
- 0.2.32
- 0.2.31
- 0.2.30
- 0.2.29
- 0.2.28
- 0.2.27
- dev-dependabot/github_actions/actions/checkout-6
This package is auto-updated.
Last update: 2026-01-07 11:46:31 UTC
README
Twig Components for HTML5 Elements
This is a Symfony Bundle which adds pre-built, typesafe, auto-generated Twig Components for all HTML5 elements. It comes with full WCAG, ARIA support, also adds support for Alpine.js attributes. It makes use of Extended HTMLDocument which is a schema-first library that improves HTML5 support in PHP 8.4. Mainly used for validation of immutable enum attributes.
This is especially useful when writing anonymous Twig Components enforcing standards-compliance, always-valid HTML5.
Features
- Symfony UX Integration: Native Symfony Twig Component support
- ARIA Compliant: Complete ARIA attribute support with proper validation
- Auto-Generated: Consistent API across all HTML5 elements via schema-first approach
- Enum Validation: Static attribute validation for HTML compliance
- Modern PHP: Requires PHP 8.4+ for DOM\HTMLDocument features
Requirements
- PHP 8.4 – the underlying Extended HTMLDocument library is built upon PHPs DOM\HTMLDocument which is available since PHP 8.4+
Since only the Enums are used for attribute validation here, adding support for older PHP versions could be done easily if it's needed or requested.
Installation
composer require vardumper/html5-twig-component-bundle
The bundle includes automatic service registration - no additional configuration needed!
Configuration
The bundle is automatically registered via Symfony Flex. If you need to register it manually, add to config/bundles.php:
# config/bundles.php return [ // ... Html\TwigComponentBundle\HtmlTwigComponentBundle::class => ['all' => true], ];
Next, tell Symfony that Twig Components can be found in a new path. Edit config/packages/twig_component.yaml and add the following:
# config/packages/twig_component.yaml twig_component: defaults: Html\TwigComponentBundle\Twig\: '%kernel.project_dir%/vendor/vardumper/html5-twig-component-bundle/src/Twig/'
All Twig Components are automatically discovered and registered through the bundle's DependencyInjection extension. No manual service configuration required!
Usage
Use any HTML element as a Twig Component:
<twig:Blockquote cite="https://example.com"> This is a quote from example.com </twig:Blockquote> <twig:Button role="button" type="submit"> Submit Form </twig:Button> <twig:Input type="email" name="email" required />
Use in anonymous Twig Components
{# templates/components/Teaser.html.twig #} <twig:Div class="teaser"> <twig:H3>{{ headline }}</twig:H3> <twig:P>{{ content }}</twig:P> <twig:A role="button" href="{{ buttonLink }}" title="{{ buttonText }}">{{ buttonText }}</twig:A> </twig:Div>
which can then be used in pages:
{# templates/page.html.twig #} {% for item in teasers %} <twig:Teaser headline="{{ item.headline }}" content="{{ item.content }}" buttonLink="{{ item.buttonLink }}" buttonText="{{ item.buttonText }}"> </twig:Teaser> {% endfor %}
Passing arrays as component props
You can pass associative arrays to component props using the : notation. For example to pass data-* attributes to the component:
<twig:Div :dataAttributes="{'role': 'article'}"> Hello world </twig:Div>
This will render a data-role="article" attribute on the generated component's root element.
Features
- ✅ All HTML5 elements supported
- ✅ Full ARIA attributes support
- ✅ Type-safe enum validation
- ✅ PreMount validation with OptionsResolver
- ✅ Proper namespace structure (Block/Inline/Void)
Components Structure
Components are organized by type:
Block- Block-level elements (div, section, article, etc.)Inline- Inline elements (span, a, strong, etc.)Void- non-rendered elements (head, wbr, meta, etc.)
Read More
- Extended HTMLDocument Documentation
- Extended HTMLDocument Github Repository
- Twig Components
- Symfony UX
Issues & Bugs
Please report issues in this packages home at Extended HTMLDocument