sk/twig-extensions-bundle
A Twig extensions bundle for PHP applications that adds reusable Twig filters, functions, and utilities to streamline template rendering. Install via Composer to keep templates cleaner, more expressive, and easier to maintain.
This release is part of SKTwigExtensionsBundle, a Symfony bundle that registers Twig extensions — not a native Laravel package. Before using it in a Laravel app, confirm how Twig is wired into your project (typically rcrowe/twigbridge or a custom Twig environment); without Twig, none of these filters/functions exist.
Minimal path:
composer require skroczek/sk-twigtwig-extensions-bundle or the version constraints your app supports) — note v1.2.0 targets PHP 7.1, so verify your runtime.StringTwigExtension on your Twig environment (Laravel).Resources/doc/StringExtension.md first — it documents the new ucfirst/lcfirst filters and functions.{{ name|ucfirst }} or {{ ucfirst(name) }}.{{ value|ucfirst }} and {{ ucfirst(value) }}). Prefer filters in templates for readability; use functions when composing inside expressions or passing into other Twig calls.StringTwigExtension and add it to your Twig environment during service provider boot:
$twig->addExtension(new StringTwigExtension());
bundles.php and let the DI extension load the Twig extension service automatically — no manual wiring needed.{{ title|lower|ucfirst }} is a clean idiom for sentence-casing single words; combine with trim when handling user input.ucfirst/lcfirst are byte-oriented, not multibyte-aware. Non-ASCII first characters (e.g. accented or CJK strings) may behave unexpectedly — use mb_*-based custom filters for i18n-sensitive text.ucfirst/lcfirst; passing null may emit deprecation notices depending on PHP version. Guard with |default('') in templates.ucfirst/lcfirst, so these are safe, but if you already registered a custom string extension, check for duplicate filter names — Twig throws on redefinition.Unknown "ucfirst" filter appears, the extension isn't registered on that specific Twig environment (common when multiple environments or cached templates exist). Clear the Twig/template cache after registering.StringTwigExtension class is a clean reference for building your own string helpers — follow its pattern of pairing filters with functions for maximum template flexibility.How can I help you explore Laravel packages today?