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

Bootstrap Bundle Laravel Package

bbit/bootstrap-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation Run composer require bbit/bootstrap-bundle:dev-master (or manually add to composer.json and update). Verify the package appears in vendor/bbit/.

  2. Enable the Bundle Add new BBIT\BootstrapBundle\BBITBootstrapBundle() to app/AppKernel.php under registerBundles().

  3. First Use Case In a Twig template, call {{ insertBootstrap() }} in the <head> or <body> section to auto-load jQuery, Bootstrap CSS/JS, and Font Awesome.

Where to Look First

  • Twig Functions: Check src/BBIT/BootstrapBundle/Twig/Extension/BootstrapExtension.php for available Twig helpers (e.g., insertBootstrap()).
  • Assets: Verify loaded files in vendor/bbit/bootstrap-bundle/Resources/public/ (Bootstrap CSS/JS, Font Awesome).
  • Config: No default config file exists; all assets are hardcoded.

Implementation Patterns

Core Workflows

  1. Asset Inclusion

    • Use {{ insertBootstrap() }} in Twig to inject:
      • jQuery (from CDN or local fallback).
      • Bootstrap CSS/JS (v3.x by default).
      • Font Awesome (v4.x).
    • Pattern: Place the Twig call in your base template (e.g., base.html.twig) to avoid repetition.
  2. Customization

    • Override Assets: Copy files from vendor/bbit/bootstrap-bundle/Resources/public/ to web/bundles/bbitbootstrap/ and modify them.
    • Version Control: Specify versions via Twig (if supported in future updates):
      {{ insertBootstrap('3.4.1', '5.15.4') }} {# CSS, JS versions #}
      
    • Exclude Components: No built-in exclusion; manually remove unwanted CSS/JS classes or use {{ ignoreBootstrap() }} (if added in future).
  3. Integration with Laravel

    • Asset Pipeline: Use Laravel Mix to process Bootstrap/Font Awesome files if you need custom builds.
    • Service Providers: Extend the bundle by binding a service provider to modify asset paths or add logic:
      // src/BBIT/BootstrapBundle/DependencyInjection/BBITBootstrapExtension.php
      // (Override or extend existing config logic)
      
  4. Dynamic Loading

    • Conditional Inclusion: Use Twig’s if to load Bootstrap only on specific routes:
      {% if app.request.get('_route') == 'dashboard' %}
          {{ insertBootstrap() }}
      {% endif %}
      

Pro Tips

  • Debugging: Check the rendered HTML source to confirm assets are loaded (look for <link>/<script> tags).
  • Caching: Clear Symfony cache (php bin/console cache:clear) after changes if assets aren’t updating.
  • Laravel-Specific: For Laravel 5.4+, use php artisan vendor:publish to publish bundle assets (if supported in future).

Gotchas and Tips

Pitfalls

  1. No Configuration File

    • Issue: Hardcoded asset versions/paths mean no easy way to customize without editing the bundle’s source.
    • Workaround: Override files in web/bundles/ or fork the repo to add config support.
  2. Version Locking

    • Issue: Using dev-master may pull unstable versions. Bootstrap 3.x is outdated (last update: 2016).
    • Workaround: Pin to a specific commit or fork to use Bootstrap 4/5:
      composer require bbit/bootstrap-bundle@dev-v1.0.0
      
  3. Asset Conflicts

    • Issue: jQuery/Bootstrap versions may conflict with other bundles (e.g., KNPBundle, StofDoctrineExtensions).
    • Workaround: Use {{ ignoreBootstrap() }} (if available) or manually include your own versions.
  4. Font Awesome Licensing

    • Issue: Font Awesome 4.x is under a non-free license. Ensure compliance with FA’s terms.
    • Workaround: Use a CDN or self-hosted version with a valid license.
  5. Laravel-Specific Quirks

    • Issue: The bundle targets Symfony; Laravel’s asset pipeline (Mix/Vite) may ignore its files.
    • Workaround: Configure Mix to process web/bundles/bbitbootstrap/ or use Laravel’s mix-manifest.json.

Debugging Tips

  • Check Loaded Assets: Inspect the <head> section for:
    <link rel="stylesheet" href="/bundles/bbitbootstrap/css/bootstrap.min.css">
    <script src="https://code.jquery.com/jquery-3.x.x.min.js"></script>
    
  • Clear Cache: Run php bin/console cache:clear and php bin/console assetic:dump (if using Assetic).
  • Log Errors: Enable Symfony’s error logging to catch missing files:
    // app/config/config.yml
    monolog:
        handlers:
            main:
                type: stream
                path: "%kernel.logs_dir%/%kernel.environment%.log"
                level: debug
    

Extension Points

  1. Custom Twig Functions

    • Extend BootstrapExtension to add helpers (e.g., insertBootstrapWithCustomJS):
      // src/AppBundle/Twig/AppExtension.php
      class AppExtension extends \Twig_Extension
      {
          public function getFunctions()
          {
              return [
                  new \Twig_SimpleFunction('customBootstrap', [$this, 'renderCustomBootstrap']),
              ];
          }
      }
      
  2. Asset Overrides

    • Publish assets to web/bundles/bbitbootstrap/ and modify them:
      # Hypothetical command (not natively supported)
      php bin/console assets:install --symlink web/bundles/bbitbootstrap
      
  3. Event Listeners

    • Hook into Symfony events to modify asset paths:
      // src/AppBundle/EventListener/BootstrapListener.php
      class BootstrapListener
      {
          public function onKernelRequest(GetResponseEvent $event)
          {
              // Modify $event->getRequest()->attributes to change asset paths
          }
      }
      
  4. Composer Scripts

    • Add a post-install script to auto-publish assets:
      {
        "scripts": {
          "post-install-cmd": [
            "php bin/console assets:install --symlink"
          ]
        }
      }
      
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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle