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 Extensions Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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:

  1. Install via Composer (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.
  2. Register the bundle in your Symfony kernel (if using Symfony) or manually register StringTwigExtension on your Twig environment (Laravel).
  3. Read Resources/doc/StringExtension.md first — it documents the new ucfirst/lcfirst filters and functions.
  4. First use case: normalizing display strings in templates, e.g. {{ name|ucfirst }} or {{ ucfirst(name) }}.

Implementation Patterns

  • Filter vs. function: the release ships both forms ({{ value|ucfirst }} and {{ ucfirst(value) }}). Prefer filters in templates for readability; use functions when composing inside expressions or passing into other Twig calls.
  • Manual registration in Laravel: if you're not running Symfony's bundle autoconfiguration, instantiate StringTwigExtension and add it to your Twig environment during service provider boot:
    $twig->addExtension(new StringTwigExtension());
    
  • Symfony bundle pattern: register the bundle in bundles.php and let the DI extension load the Twig extension service automatically — no manual wiring needed.
  • Chain with existing filters: {{ title|lower|ucfirst }} is a clean idiom for sentence-casing single words; combine with trim when handling user input.
  • Testing pattern: since this release adds PHP 7.1 test coverage, mirror the upstream tests in your own suite if you wrap the extension — assert filter and function behavior since both are exposed.

Gotchas and Tips

  • This is not a Laravel package. There's no service provider, facade, or config file from upstream. Any Laravel integration is your responsibility (Twig bridge or manual extension registration).
  • PHP 7.1 target: v1.2.0 explicitly tests against 7.1. Modern PHP 8.x apps should smoke-test the extension, but the string functions used are trivial and generally forward-compatible.
  • 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.
  • Null/empty handling: these are thin wrappers over PHP's ucfirst/lcfirst; passing null may emit deprecation notices depending on PHP version. Guard with |default('') in templates.
  • Name collision risk: Twig core does not define ucfirst/lcfirst, so these are safe, but if you already registered a custom string extension, check for duplicate filter names — Twig throws on redefinition.
  • Debugging: if 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.
  • Extension point: the StringTwigExtension class is a clean reference for building your own string helpers — follow its pattern of pairing filters with functions for maximum template flexibility.
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.
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle