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

Html Extra Laravel Package

twig/html-extra

Twig extension adding data_uri, html_classes, and html_cva filters/functions for generating RFC 2397 data URLs, conditionally joining class names, and managing class variants with Cva objects.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit. Unchanged. This is not a Laravel package — it is a Twig extension published under the twigphp organisation, the same group that maintains Twig itself. It contributes template-level helpers (data_uri, html_classes, html_cva, html_attr, and — as of v3.29.0 — a standalone attribute-value primitive extracted from html_attr) and has no service container, config, migration, or database footprint. Architectural fit remains entirely conditional: near-zero-cost if Twig 3.x is already the rendering engine, a poor fit if the stack is Blade-first. Laravel's default view layer is Blade, so the realistic adoption scenario is still a Laravel application that has already introduced Twig via a bridge (twig/laravel or similar), or a polyglot estate where Symfony services already render with Twig.

Scope and value. v3.29.0 is a small but substantive release with two distinct signals.

  • Feature (#4895): htmlAttrValue() is extracted from html_attr so a single attribute value can be rendered and escaped independently of the whole attribute string. This is the more strategically interesting item: it gives design-system authors a way to build bespoke attribute helpers (e.g. style, aria-*, data attributes with typed values) on top of a supported, tested primitive instead of hand-rolling escaping in templates. For an organisation standardising component APIs, that is a genuine extensibility hook — but it also means the package is now a substrate others will build on, which raises the bar on version pinning.
  • Bug fix (#4916): html_attr was dropping style declarations whose value is 0 (e.g. flex-grow: 0, margin: 0, z-index: 0). This is a correctness bug with real visual consequences — silently missing layout rules — and its presence in the codebase until now is a reminder that these helpers are small parsers, not trivial string concatenation.

The highest-leverage item for a product organisation remains html_cva, because it moves variant logic out of ad-hoc template conditionals and into a declared, reviewable contract. htmlAttrValue is second: it makes the design-system contract composable.

Governance and signal quality. Stars (~80) and registry dependents (0) remain misleading. The package is effectively first-party infrastructure, distributed within the Twig ecosystem and pulled in transitively by Symfony's TwigBundle, which the registry's dependent count does not capture. Discount the composite score (20.2) as metadata sparsity, not a maintenance verdict. Two observations from this release: (a) the project ships frequently and fixes reported defects promptly, which is a positive velocity signal; (b) documentation drift persists — the README still under-enumerates the function surface, and the newly extracted htmlAttrValue() will not appear there immediately. Treat CHANGELOG and source as authoritative.

Technical risk.

Risk Severity Notes / Mitigation
Rendering-engine mismatch (Twig vs Blade) High Do not adopt Twig to obtain this package. Gate on Twig already being present.
CSP breakage from data: URIs Medium Inline data_uri output violates strict img-src/style-src policies. Audit CSP before enabling; scope to email/offline contexts.
SVG data_uri payload risk Medium Data-URI SVGs bypass some sanitisers and can carry script. Restrict to raster or trusted, sanitised sources.
Silent markup change on minor bump Medium The #4916 fix alters rendered output for any template using zero-valued style declarations. Snapshot-test rendered attributes before upgrading.
Helper correctness bugs (parser edge cases) Medium html_classes/html_attr parse CSS-like input; edge cases surface as visual defects, not exceptions. Add visual regression coverage on component primitives.
Extension not registered / partial registration Medium A new primitive means a possible partial upgrade where html_attr works but htmlAttrValue is absent. Assert availability per function.
Upstream major-version coupling Medium Extension tracks Twig majors; a Twig 4 will force a coordinated bump.
Documentation gaps Low Budget for internal docs covering the extracted primitive and its escaping contract.
Payload bloat Low–Medium Base64 inflates size ~33% and defeats CDN/browser asset caching.

Key questions.

  1. Is Twig an existing, deliberate architectural decision, or would this package be the tail wagging the dog?
  2. Does a design-system need for typed variants exist, and is html_cva the right home for it versus a build-time CSS tool (Tailwind, vanilla-extract, CVA in JS)?
  3. Who owns template-level conventions — frontend platform or product teams?
  4. Will teams build custom attribute helpers on htmlAttrValue()? If so, that code becomes an internal API surface and needs an owner, tests, and a pinned minor version.
  5. What is the CSP posture, and where is data_uri legitimately useful (transactional email, offline HTML exports) versus harmful?
  6. For a Blade shop, what is the true alternative cost of @class plus a small custom directive?
  7. Does anyone own visual-regression coverage of rendered attributes, given that this release changed output without changing the API?

Integration Approach

Stack fit. Best fit: Symfony applications (auto-registered by TwigBundle, zero wiring) and Laravel applications that have already committed to Twig. Weak fit: vanilla Laravel/Blade, where @class and Blade components cover the class-merging case and a custom directive costs less than a parallel templating engine. Neutral fit: Laravel + Inertia, where templating is largely client-side and these helpers have no surface.

Integration mechanics. Installation remains a single Composer requirement. Unlike Symfony, Laravel will not auto-register the extension — it must be added explicitly to the Twig environment during bootstrap. That is a handful of lines, but it is a persistent configuration obligation mirrored across local, CI, and production, and it needs a test asserting registration so a refactor cannot silently drop it. With v3.29.0, extend that test to assert function-level availability (html_attr, htmlAttrValue, html_cva), not just extension presence — otherwise a partial or skipped upgrade will fail only at render time in production.

Compatibility. Twig 3.x is the floor; the package version line moves with Twig's. Pin the minor version explicitly — v3.29.0 already contains behaviour-affecting changes. Because htmlAttrValue is brand new and undocumented upstream, confirm exposure (function name, filter vs function, signature) against the installed source rather than the README. Validate against the Laravel LTS in use and against the specific Twig bridge version, since bridge lag is the most likely source of a broken install.

Migration path (only if Twig is already present).

  1. Audit — inventory existing conditional-class patterns, inline asset embeds, and hand-rolled attribute output. Identify components with the highest variant churn and any template that builds attributes by string concatenation; the latter are htmlAttrValue candidates.
  2. Baseline — capture snapshot tests of rendered component markup on the current version before bumping, so the #4916 output change and any future parser fixes surface as reviewable diffs rather than production surprises.
  3. Pilot — upgrade to v3.29.0, convert one component (typically a button or badge) to html_cva, and use htmlAttrValue on one bespoke attribute helper. Measure template line count, review comments, and render time before and after.
  4. Standardise — publish a short internal style guide: when to use html_classes versus html_cva, where data_uri is permitted, and how to build custom helpers on htmlAttrValue without extending its trust boundary to user input.
  5. Enforce — add template linting (twigcs, twig:lint, PHPStan's Twig rules) plus the attribute snapshot tests to CI so conventions and output stability survive staff turnover.

Sequencing note. Do not sequence this ahead of a Twig decision. If Twig is not present, defer and re-evaluate only when Twig adoption is independently justified. If Twig is present, this remains a one-sprint, low-ceremony addition; the v3.29.0 upgrade itself is a patch-level task, but budget a half-day for installing the attribute snapshot tests that make the upgrade safe.

Operational Impact

Maintenance. The ongoing burden is close to nil: no runtime services, no persistence, no scheduled jobs, MIT licensed, semantic versioning, and an upstream steward with an interest in keeping it aligned with Twig. The real maintenance cost is template literacy, plus — newly — ownership of any internal helpers built on htmlAttrValue. Those helpers are ordinary application code and will be maintained by whoever owns the component library, not by the platform team. Budget for a one-page internal reference, a linting rule, and a snapshot-test fixture, not for a support rota.

Support. Upstream documentation is deliberately thin: the README lists a subset of functions and defers to Symfony's Twig documentation for semantics. The gap widens with each release — v3.29.0 adds a primitive that will not be documented for some time. Expect internal questions about escaping behaviour, CVA immutability, the exact semantics of htmlAttrValue when passed arrays or null, and which contexts permit data_uri. Pre-empt them in the style guide. Escaping deserves emphasis: html_attr, html_classes, and htmlAttrValue emit markup-ready strings, and reviewers must confirm that trust boundary is not extended to user-supplied values.

Scaling. Rendering cost is negligible; these are string operations over small inputs, and Twig compiles templates to PHP, so per-request overhead is a function of template caching, not of this package. Configure and warm the Twig cache in deployment, and wire cache invalidation into the standard view:clear path so template changes are not silently stale across a multi-server fleet. The genuine scaling concern remains payload: inlined data URIs inflate HTML, bypass CDN and browser asset caching, and repeat on every request. Set a size ceiling (commonly ~10KB) and confine data_uri to assets that must be self-contained — transactional email, exported HTML, and print artefacts.

Failure modes.

Failure Impact Mitigation
Extension not registered in a new environment Template render error, 500s Registration smoke test in CI; config-as-code
Partial upgrade (extension present, new function absent) Render error on components using htmlAttrValue Assert function-level availability in the smoke test
Unreviewed output change from a helper fix (e.g. #4916) Subtle layout regressions shipped silently Snapshot tests of rendered attributes; review diffs on every bump
CSP blocks emitted data: URIs Broken images, silent UX degradation CSP audit; restrict to email/export paths
Malicious or malformed asset reaches data_uri XSS via SVG data URI Sanitise sources; allowlist extensions
Custom helper on htmlAttrValue extends trust to user input Injection / escaping bypass Treat helper output as markup; never pass unvalidated user strings
Twig major upgrade outpaces extension release Blocked framework upgrade Pin versions; track upstream release cadence
Cache not invalidated on deploy Stale markup in production Wire Twig cache into deploy and clear commands
Convention drift after the champion leaves Inconsistent templates, rework Lint rules plus documented style guide

Ramp-up. An engineer already fluent in Twig needs under a day to be productive; a Blade-only team needs one to two weeks to become comfortable with Twig's syntax, escaping model, and error surfaces before this package is even relevant. v3.29.0 does not change that calculus — htmlAttrValue is trivially learnable once Twig is understood, and adds perhaps an hour to onboarding. That asymmetry remains the decisive operational fact: the package is cheap, but the prerequisite skill is not. Frame adoption as "a marginal add-on to an existing Twig investment," never as a standalone improvement, and make the go/no-go decision on Twig availability rather than on this package's merits.

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.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
adachsoft/php-code-style