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

Html Extra Laravel Package

twig/html-extra

Twig HTML Extension adds handy helpers to Twig: a data_uri filter for RFC 2397 data URLs, an html_classes function to conditionally build CSS class strings, and an html_cva function for managing class variants via a Cva object.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Frontend Templating Modernization: Accelerates migration from Blade to Twig for dynamic, component-driven UI (e.g., marketing sites, admin dashboards) by providing native Twig utilities for HTML/CSS logic.
  • Design System Scalability: Enables consistent class variant generation (html_cva) for design systems (e.g., Tailwind, Bootstrap) without hardcoding logic in templates or JavaScript.
  • Performance Optimization: Reduces HTTP requests via data_uri for small assets (e.g., icons, SVGs), improving perceived load speed—critical for SEO and mobile UX.
  • Build vs. Buy: Avoids reinventing utility functions (e.g., class merging, data URIs) that would otherwise require custom JavaScript, PHP helpers, or CSS preprocessors.
  • Roadmap Alignment:
    • Laravel + Inertia.js: Supports server-side rendering of dynamic UI (e.g., feature flags, A/B tests) with Twig’s logic.
    • Headless CMS: Ideal for templating systems (e.g., Strapi, Contentful) where content editors define class variants without touching code.
    • Dark Mode/Theming: Enables runtime class toggling (e.g., dark-mode class) via html_cva without rebuilds.
  • Use Cases:
    • Conditional UI: Dynamic classes for user roles (e.g., admin-only styles).
    • Embedded Assets: Inline SVGs/icons for offline-first apps or reduced bundle size.
    • Component Libraries: Reusable Twig macros with preconfigured class variants.

When to Consider This Package

  • Adopt if:

    • Your team uses Twig (or is evaluating it for Laravel/Inertia) and needs HTML/CSS utilities beyond Blade’s capabilities.
    • You manage complex class logic (e.g., responsive variants, dark mode, feature flags) that’s currently handled via:
      • Manual string concatenation in templates.
      • Custom JavaScript (e.g., classList.add()).
      • CSS preprocessors (Sass mixins) for variant generation.
    • You prioritize RFC-compliant solutions (e.g., data_uri for embedded assets) to avoid vendor lock-in.
    • Your frontend relies on dynamic styling (e.g., theming, A/B tests) without full CSS-in-JS (e.g., styled-components).
  • Look elsewhere if:

    • You’re all-in on Blade and lack Twig expertise—custom Blade directives may suffice for class merging.
    • Your needs are static: No dynamic classes, data URIs, or variant generation.
    • You use CSS-in-JS (e.g., Emotion, styled-components) where class logic is handled at runtime.
    • Your team prefers utility-first CSS (e.g., Tailwind) over Twig-based variant generation.
    • You’re building a non-HTML application (e.g., API, CLI tool).

How to Pitch It (Stakeholders)

For Executives: "This package lets our frontend team build dynamic UIs faster by handling repetitive HTML logic (like class variants or embedded assets) in Twig—cutting dev time by 30% while improving consistency. For example, we can toggle dark mode or A/B test styles without JavaScript rebuilds. It’s a lightweight, MIT-licensed tool that aligns with our Twig/Inertia roadmap and reduces bundle size by embedding small assets (like icons) directly in HTML. Let’s pilot it for [Component X] to measure impact."

For Engineers: *"Twig/html-extra gives us three game-changers for Laravel/Twig:

  1. data_uri: Embed SVGs/icons inline (e.g., {{ 'icon.svg'|data_uri }}) to eliminate HTTP requests for small assets.
  2. html_classes: Safely merge classes conditionally (e.g., {{ 'btn'|html_classes({'primary': isAdmin}) }})—no more string concatenation bugs.
  3. html_cva: Generate class variants programmatically (e.g., {{ 'btn'|html_cva({ 'size': 'md' }) }}) for design systems or theming.

Why now?

  • We’re migrating [Component Y] to Twig/Inertia—this fills the gap for dynamic HTML.
  • It’s lighter than CSS-in-JS for simple variants and more maintainable than manual class strings.
  • Works alongside Blade (e.g., Twig for dynamic parts, Blade for Laravel logic).

Proposal: Let’s replace our custom ClassBuilder class with html_cva in the [Dashboard] and measure template complexity reduction. If it cuts our Twig templates by 20%, we’ll expand to [Component Z]."*

For Designers: *"This tool lets you define UI variants once (e.g., button sizes, colors) and reuse them across templates without touching code. For example:

  • Create a ‘primary’ button style in Twig: {{ 'btn'|html_cva({ 'primary': 'bg-blue-600' }) }}.
  • Toggle dark mode by swapping a single class: {{ 'body'|html_classes({'dark': isDarkMode}) }}. No more CSS hacks or JavaScript—just pure HTML logic. Want to see how it works for [Component A]?"*
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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
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