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

Twig Tailwind Extra Laravel Package

tales-from-a-dev/twig-tailwind-extra

A Twig extension adding Tailwind CSS filters: tailwind_merge() integrates tailwind-merge-php to resolve conflicting utility classes, while tailwind_classes() builds mergeable class lists for Twig's html_attr() and html_attr_merge(). Requires PHP 8.1+, Twig 3+, and Tailwind 4+.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

Build vs. buy for class-conflict resolution. Every Tailwind component that accepts overrides (size, variant, class) eventually needs "merge, don't concatenate" semantics — last-wins per utility group. The naive alternative is a hand-rolled PHP helper or scattered array_merge/implode calls in templates, which silently breaks the moment you add p-4 after p-2. This package is a thin, MIT-licensed buy decision (~2 filters) that removes that internal maintenance line item.

Component API design. If you want templates that behave like components — {% include 'button.twig' with { class: 'bg-red-500' } %} where the caller's classes beat the defaults — tailwind_merge() is the enabling primitive. That decision (do our Twig components accept an override prop, or do we force full class replacement?) is a product/API decision, not an implementation detail, and it gates how reusable your design system can be.

Server-side vs. build-time class resolution. This package keeps merging in the rendering layer. That is the right call when class lists are computed from runtime state — feature flags, per-tenant theming, CMS-entered field values, role-based UI density. If your classes are all static and known at build time, you don't need it and shouldn't adopt it.

Templating engine strategy. The package is Twig-only. For a Laravel-first roadmap this is a negative signal: Laravel ships Blade, and adopting Twig means a bridge package plus a parallel template ecosystem. This package is a fit for Symfony, Craft CMS, Drupal, or Slim+Twig services. If someone proposes it inside a Blade codebase, that's a signal that the team is considering a Twig migration — treat it as a roadmap question, not a dependency question.

Caching and performance posture. Two layers are already handled — a Symfony cache.system pool plus a 500-entry in-memory LRU — so the "does this hurt render time?" objection is largely pre-empted. Worth noting for capacity planning on high-render-count pages.

Vendor-risk tolerance. 40 stars and 0 dependents means you are effectively an early adopter, not part of a crowd. That's a deliberate risk-acceptance decision for a small, single-purpose, easily-vendored dependency — reasonable here because the surface area is tiny and the license permits forking.

When to Consider This Package

Adopt when all of these hold:

  • Twig 3 or 4 is already your template engine (Symfony bundle path is supported; standalone Twig install is documented).
  • Tailwind v4 is in use, or you are committing to it — merge semantics are version-sensitive and v1.x targets Tailwind 4.
  • PHP 8.1+ and standard Composer workflow.
  • You have at least a few components where caller overrides must beat defaults; if you have none, the dependency earns nothing.
  • You accept a low-adoption dependency for a small, replaceable capability, and you are willing to pin the minor version and diff merge output on upgrade.

Look elsewhere when:

  • You are on Laravel/Blade. No native fit; you'd need a Twig bridge, and the equivalent capability in Blade is a small custom directive or a PHP helper. The cost/benefit flips.
  • You are on Tailwind 2/3. The underlying merger assumes modern Tailwind semantics; class-prefix and plugin-generated utilities are the usual failure points. Validate against your actual tailwind.config.js before committing.
  • Your classes are static. If nothing is computed at runtime, tailwind-merge at the JS build layer — or simply disciplined class authoring — is simpler and has no PHP runtime cost.
  • You need vendor guarantees. One primary maintainer, 0 dependents, and a versioning policy that explicitly allows merged-output changes in minor releases. If your org requires stability SLAs or a support contract, this fails the bar.
  • Template-level merging is the wrong layer for you. If your design system resolves variants in a typed PHP/TS layer before render, this duplicates that responsibility.

Practical gate before adoption: run your own class vocabulary through both merge paths and diff the output. Arbitrary values, stacked variants (dark:hover:md:), and prefix configs are where behavior moves.

How to Pitch It (Stakeholders)

To executives (one paragraph): We're evaluating a small, MIT-licensed Twig extension that stops Tailwind class conflicts from reaching the browser. The problem it solves is concrete: when a reusable component lets a caller override styles, naive string concatenation produces broken layouts that are expensive to debug in QA. This package adds two template filters that resolve conflicts automatically. It is a low-cost, low-blast-radius dependency — roughly two functions, easily forked or replaced — and it lets us offer reusable UI components with a clean override API instead of copying templates. The trade-off is vendor risk: it has a single maintainer and minimal external adoption, so we treat it as a pinned, replaceable utility rather than strategic infrastructure.

To engineering (the ask): Add the extension, expose tailwind_merge() and tailwind_classes() in templates, and standardize on "components accept an override class prop." Pre-requisites: Twig 3/4, PHP 8.1+, Tailwind 4. Caching is already built in (Symfony cache pool + in-memory LRU), so the perf story is fine. Three things to own before merge: (1) pin the minor version, because the maintainer's semver policy allows merged output to change in minor releases when the underlying merger fixes bugs; (2) add a golden-file test over our real class vocabulary so upgrades produce a diffable failure instead of a visual regression; (3) confirm our Tailwind config — prefixes, plugins, custom theme extensions — is handled by the current merger. Note for the Laravel side: this is a Twig package, so it does not apply to Blade templates without a bridge; if a Blade team wants equivalent behavior, budget a small in-house helper rather than pulling this in.

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.
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode