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

Product Decisions This Supports

  • Template-layer buy vs. build: Deciding whether to hand-roll HTML helper logic (conditional class merging, data-URI encoding, attribute rendering) or adopt a small, maintained upstream extension. This package is the "buy" option for four narrow, well-defined template utilities: data_uri (RFC 2397 inline assets), html_classes (conditional class joining), html_cva (class-variant objects for component styling), and html_attr (ergonomic HTML attribute output). v3.29.0 adds a fifth, lower-level primitive: htmlAttrValue() (see below), which nudges this from "four conveniences" toward "a thin, composable attribute layer."
  • Templating engine strategy: The single biggest product decision this informs is Twig vs. Blade. Adoption only makes sense if Twig is already, or will become, part of the rendering stack (via twig/laravel). In a Blade-first Laravel app, the same outcomes are largely covered by Blade's @class, @style, and component attributes — so this is a "do not adopt" signal, not a feature gap.
  • Component-library and design-system roadmap: If you're investing in a reusable UI component library, html_cva gives you a typed, template-side variant API (size, intent, state) instead of scattered ternaries. That is a real lever for design-system consistency and for onboarding designers into templates. New in v3.29.0: htmlAttrValue() exposes attribute value rendering separately from full tag output, which lets component partials assemble attribute fragments (a style string here, a class string there) and hand them to a parent tag — a small but real enabler for layered component composition rather than monolithic attribute blobs.
  • Transactional email and asset-inlining roadmap: data_uri is the strongest standalone use case — email clients strip external assets, so inline base64 icons/logos materially improve email rendering fidelity without a build-step dependency.
  • Feature-flag and theming delivery: html_classes supports conditional UI states (dark mode, A/B cohorts, entitlement-driven styling) at the template layer rather than in PHP/JS, which shortens the loop between flag definition and visible UI change.
  • Rendering-fidelity quality gate (new): v3.29.0 fixes a bug where html_attr silently dropped style declarations whose value is 0 (e.g. margin: 0, border-radius: 0, opacity: 0). This is the kind of defect that produces "why does this card have unexpected spacing in Twig but not in the styleguide?" tickets. It is now fixed, but it sets a floor: if you adopt html_attr, pin to >= 3.29.0 and treat pre-3.29 output as untrustworthy for zero-valued styles.
  • Use cases worth prototyping: marketing/landing pages with variant-heavy CTAs, admin panels with dense state-driven styling, email templates, and any Twig-based component partials. Not a fit for API-only services, CLI tools, or JSX/Vue/React frontends.

When to Consider This Package

Adopt if:

  • Twig is already installed or formally on the roadmap (Laravel + twig/laravel, Symfony, or standalone Twig 3.x).
  • You have a component library where class-variant logic (html_cva) and conditional classes (html_classes) recur across dozens of templates.
  • You need RFC-compliant inline assets (data_uri) for email templates or small icon sets where an extra HTTP request is undesirable.
  • You want composable attribute rendering — with htmlAttrValue() you can produce attribute values in one partial and render them in another, instead of duplicating string-concatenation logic across components.
  • You want a small, MIT-licensed, upstream-maintained extension (twigphp org) rather than owning custom Twig extensions.

Look elsewhere if:

  • You're Blade-first. Blade's @class/@style directives and anonymous components cover the majority of the value; adopting Twig purely to get these helpers is a net negative in migration cost, hiring, and tooling.
  • Your team has no Twig experience — the learning curve is real for contributors raised on Blade, and template errors surface as 500s in production.
  • You need CSS-in-JS capabilities, runtime style computation, or framework-level theming; html_cva is string assembly, not a styling engine.
  • Your styling needs are static. If classes are hardcoded, all four helpers are dead weight — and htmlAttrValue() does not change that.
  • You need validated style output. Even on 3.29.0 this is string assembly; nothing here parses or normalizes CSS.

Validation caveats a PM should weigh:

  • ~80 stars and 0 dependents is thin ecosystem validation. The mitigating factor is stewardship: this is an official twigphp package with a real, ongoing release cadence (v3.24.0 → v3.28.0 → v3.29.0), so abandonment risk is lower than the raw numbers suggest — but it is not zero, and it is not a "safe default" you can assume review boards will wave through. The v3.29.0 bug fix supports the stewardship argument: a non-maintained package would not have caught a zero-value style edge case.
  • Version pinning is now a hard requirement, not a preference. Pre-3.29.0 html_attr can silently drop 0-valued style declarations. Any spike or benchmark run on an older version should be discarded and re-baselined on 3.29.0, or you will under- or mis-read the helper's fitness for style-heavy components.
  • Confirm the Twig/laravel bridge is maintained in your Laravel version before committing; that bridge, not this package, is the actual integration risk.
  • Treat it as a tactical dependency: four small functions plus one value-level helper. Contain it behind a small set of shared partials so removal is a day's work, not a quarter's.
  • The new htmlAttrValue() is a public API surface with one release behind it; assume minor churn and avoid spreading it across every component in the first pass.

How to Pitch It (Stakeholders)

For executives (30 seconds): "This is a small, free, officially maintained add-on for Twig, the templating engine. It gives our frontend team ready-made helpers for repetitive HTML chores — merging CSS classes conditionally, generating style variants for buttons and cards, embedding small images directly in the page or in emails, and now assembling HTML attribute fragments for reusable components. The value is speed and consistency in our component library, not new capability. The newest release also fixed a subtle bug where certain style values (things like margin: 0) were being silently dropped — a good sign that the project is actively maintained, but also a reason to pin a minimum version. The catch remains: it only pays off if we're already using Twig. If we stay on Blade, we should skip it and use Blade's built-in equivalents. My recommendation is unchanged: a one-sprint spike on a single component before any broader commitment."

For engineering: "It's still a small, MIT, no-Laravel-coupling Twig extension registered in config/twig.php. Core API unchanged: data_uri (RFC 2397 inline assets — the real win for email), html_classes (safe conditional class joining), html_cva (immutable variant objects), html_attr (attribute output). v3.29.0 brings two things that matter to us: (1) a fix for html_attr dropping style declarations with a 0 value — so pin >= 3.29.0, and re-run any earlier spike results, because that bug would have made html_attr look worse or better than it is depending on the component; (2) htmlAttrValue() extracted from html_attr, letting us render attribute values standalone and compose attribute fragments across partials instead of concatenating strings by hand. It's a nice-to-have, not a reason to adopt — one release of API history, so keep usage narrow initially. No service-container pollution, no runtime I/O, renders at normal view speed. Asks before commit: (1) confirm the twig/laravel bridge is healthy on our Laravel version, (2) lint templates in CI — a Twig syntax error is a 500 in prod, (3) add a regression fixture asserting style="margin: 0" survives rendering, so we don't re-introduce that class of bug through our own wrapping. html_cva still overlaps with Tailwind/PostCSS; I want to prove it removes code rather than adding a second styling idiom."

Ask / decision requested: unchanged — a timeboxed spike on one variant-heavy component, with an explicit exit criterion: reduce that component's template complexity without introducing a parallel styling convention. Add one condition: run the spike on v3.29.0+ and include a zero-value-style regression case. If Twig isn't already in the stack, the answer is still no, and the money is better spent on Blade component hygiene.

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