Weave Code
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

ajgl/twig-extensions-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Check Deprecation Notice: Since this bundle is deprecated in favor of AjglBreakpointTwigExtension, verify if the new package meets your needs before proceeding.
  2. Installation (Legacy):
    composer require ajgl/twig-extensions-bundle:0.1.*
    
  3. Enable Bundle (Symfony 2.x): Add to AppKernel.php:
    new Ajgl\TwigExtensionsBundle\AjglTwigExtensionsBundle(),
    
  4. First Use Case:
    • The bundle likely provides Twig filters/tags for common tasks (e.g., responsive breakpoints, utility functions).
    • Test in a Twig template:
      {{ 'text'|some_extension_filter }}
      
    • Refer to the deprecated ajgl/twig-extensions package for available extensions (e.g., breakpoint, slugify).

Implementation Patterns

Core Workflows

  1. Breakpoint Handling (Primary Use Case):

    • Use the breakpoint filter to apply responsive logic:
      {% if 'mobile' in breakpoint %}
          {{ include('mobile-layout.html.twig') }}
      {% endif %}
      
    • Define breakpoints in config (if supported) or pass them as arguments.
  2. Utility Extensions:

    • Slugify: Convert strings to URLs:
      {{ 'Hello World'|slugify }}  {# => "hello-world" #}
      
    • Truncate: Limit text length:
      {{ long_text|truncate(50) }}
      
  3. Integration with Symfony Forms:

    • Extend form themes to use Twig extensions:
      {% extends 'form_div_layout.html.twig' %}
      {% block label %}{{ form.label|upper }}:{% endblock %}
      

Best Practices

  • Replace with AjglBreakpointTwigExtension: Migrate to the new package for active maintenance:
    composer require ajgl/breakpoint-twig-extension
    
    Usage:
    {% if breakpoint('mobile') %}
        Mobile content
    {% endif %}
    
  • Custom Extensions: If the bundle allowed extensions, register new Twig functions/filters in services.yml:
    services:
        app.twig.my_extension:
            class: App\Twig\MyExtension
            tags:
                - { name: twig.extension }
    

Gotchas and Tips

Pitfalls

  1. Deprecation Risk:

    • The bundle is unmaintained (0 stars, no dependents). Avoid in production unless absolutely necessary.
    • Migration Path: Prioritize AjglBreakpointTwigExtension for breakpoints.
  2. Symfony 2.x Only:

    • Requires Symfony 2.1+ (composer.json). Incompatible with Symfony 3+ without backporting.
  3. Limited Documentation:

  4. No Configuration:

    • Likely uses hardcoded defaults (e.g., breakpoints). Override via Twig globals or custom extensions.

Debugging Tips

  • Check Registered Extensions: Dump Twig environment in a controller:
    $extensions = $twig->getExtensions();
    print_r(array_keys($extensions)); // Look for "AjglTwigExtensions"
    
  • Fallback to Core Twig: Replace deprecated extensions with native Twig filters (e.g., replace for slugify).

Extension Points

  • Override Breakpoints: If the bundle exposes a service, bind a custom breakpoint provider:
    services:
        ajgl.twig.breakpoint_provider:
            class: App\Service\CustomBreakpointProvider
            arguments: ['@request_stack']
    
  • Add New Filters: Extend the bundle’s AjglTwigExtensions class (if open-source) or create a wrapper service.

Performance

  • Avoid Heavy Filters in Loops: Twig extensions are processed per template render. Cache complex logic in PHP.
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.
monarobase/country-list
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity