jdecool/twig-constant-accessor-bundle
Symfony bundle that integrates a Twig extension for reading PHP class constants and enum cases directly in templates. It exposes a dedicated accessor function so shared values can stay in PHP while remaining easy to use in Twig, without writing custom extensions.
constant('App\\Enum::VALUE') function, so the core capability this bundle wraps is available with zero dependencies. This package mainly adds namespace-prefix configuration (so templates can write constant('STATUS_ACTIVE') instead of a fully-qualified path) and a small DX layer. That makes the real decision "add a dependency vs. write ~50 lines," not "buy vs. build."Consider it (or, more realistically, copying the extension class into your codebase) when:
Look elsewhere — or just use the built-ins — when:
constant() function has the same DX win minus the prefix sugar, and it's maintained by the Twig team.const declarations, and neither this bundle nor Twig's built-in solves that properly.constant() over a wrapper.Recommended default: treat this as a reference implementation, not a dependency. Read it, reimplement the ~1 extension class internally, and keep your dependency count flat.
For executives: This is a small, low-risk developer-ergonomics utility — not a product capability. It lets templates reference PHP constants by short name instead of long class paths, which reduces typo-driven display bugs and makes views easier to read. The catch: it's a Symfony-only bundle that is archived and unmaintained, with negligible community adoption. We should not take a dependency on it. The honest recommendation is to not add it to the stack, and if a team genuinely wants the ergonomics, spend roughly a day replicating the behavior in-house so we own it. Cost of adoption is near zero; cost of depending on it is future upgrade friction, which we avoid entirely by building the small piece ourselves.
For engineering: Twig's built-in constant() already covers 90% of the value. The bundle's increment is configurable namespace prefixes so templates can write constant('STATUS_ACTIVE'). Repo is archived, last release 2024-05-02, 9 stars, 0 dependents — no upstream support and no compat guarantees past the Twig version it targets. Recommend: vendor the extension class (MIT licensed, attribution required), add a unit test around the prefix resolution, and pin your Twig major version. Do not add it to composer.json.
How can I help you explore Laravel packages today?