zicht/twig-classes
A Twig extension for building CSS class lists in templates. Add classes conditionally, merge class arrays, and output clean class attributes without messy inline logic, keeping Twig markup readable and maintainable in Laravel/PHP projects.
zicht/twig-classes is a thin adapter that exposes zicht/classes (a PHP helper for composing CSS class lists, BEM-style modifiers, and conditional classes) inside Twig templates. The decision it informs is whether class-name composition belongs in PHP helpers invoked from templates, or in Twig macros/filters you own.is-active when state is X, append a modifier when size is Y" stay in templates and out of controllers/view models, instead of accumulating as string concatenation in Twig or duplicated per-component.Consider it when all of the following hold:
zicht/classes as the underlying class-name builder — this package is worthless without it.Look elsewhere — or build in-house — when:
clsx, classnames, cn) are mature and better supported; this package adds nothing there.{% apply %}/macro patterns, twig/html-extra, or TwigComponent-adjacent tooling may cover the need with better bus-factor characteristics.Recommended framing for engineering: treat it as a reference implementation. Read the source, confirm it is a trivial wrapper, and decide between composer require and a 30-line internal Twig extension you own.
One line: A small Twig extension that lets templates compose CSS class names cleanly and conditionally, replacing scattered string concatenation with a single, testable helper — but it is a low-adoption, single-vendor package, so we should adopt the pattern rather than lean on the dependency.
For executives: This is not a platform decision, it is a hygiene decision. Class-name logic scattered across templates is a known source of UI inconsistency and slow, error-prone styling changes — especially across a multi-client or multi-brand portfolio. A shared class helper makes design-system changes cheaper and makes UI regressions less likely. Cost is negligible; the real recommendation is to standardize the pattern internally rather than depend on an unsupported third-party package for it.
For engineering: zicht/twig-classes exposes zicht/classes as a Twig filter/function. It solves a real annoyance — conditional and BEM modifier composition in templates — with minimal surface area. Risks: single maintainer, no adoption signal, no compatibility guarantees across Twig majors, and an implicit hard dependency on zicht/classes. Proposal: 1–2 hours to evaluate the source, then either pin and vendor it or reimplement equivalent behavior as an internal Twig extension under our own ownership. Either way we get consistent class output, and we avoid a silent dependency we cannot maintain.
Ask: Approval for a timeboxed spike (≤1 day) and a decision gate — adopt, vendor, or reimplement — before any team standardizes on it.
How can I help you explore Laravel packages today?