Install via Composer:
composer require mopa/bootstrap-bundle
Ensure your composer.json aligns with your Symfony version (e.g., ^4.4|^5.1|^6.0 for v3.4).
Enable the Bundle:
Add to config/bundles.php:
return [
// ...
Mopa\Bundle\BootstrapBundle\MopaBootstrapBundle::class => ['all' => true],
];
First Use Case:
Inject the MopaBootstrapBundle services into a controller or Twig template:
{{ mopa_bootstrap_include_css() }}
{{ mopa_bootstrap_include_js() }}
Render a Bootstrap component (e.g., alert):
{{ mopa_bootstrap_alert('Success!', 'success') }}
Key Files:
Resources/doc/ for version-specific guides.Resources/views/ for Twig templates (e.g., alert.html.twig).DependencyInjection/Configuration.php for bundle configuration.Asset Management:
mopa_bootstrap_include_css() and mopa_bootstrap_include_js() in your base layout (base.html.twig) to avoid duplication.# config/packages/mopa_bootstrap.yaml
mopa_bootstrap:
assets:
css: '/custom/path/bootstrap.min.css'
js: '/custom/path/bootstrap.bundle.min.js'
Component Integration:
{{ form_widget(form, {'attr': {'class': 'form-control'}}) }}
{{ mopa_bootstrap_modal('my-modal', 'Modal Title') }}
{% block mopa_bootstrap_modal_my_modal_body %}
<p>Modal content here.</p>
{% endblock %}
Dynamic Theming:
mopa_bootstrap:
theme: 'bootstrap-theme.css' # e.g., 'bootstrap-theme.min.css'
{% set theme = 'bootstrap-theme.css' %}
{{ mopa_bootstrap_include_css({'theme': theme}) }}
JavaScript Integration:
{{ mopa_bootstrap_javascript('
$(document).ready(function() {
$("[data-toggle=tooltip]").tooltip();
});
') }}
Custom Templates:
alert.html.twig) in:
templates/bundles/MopaBootstrapBundle/
encore.addEntry() to bundle Bootstrap assets alongside your JS/CSS.# config/packages/framework.yaml
assets:
version: 'unique-version-string'
Asset Loading Order:
webpack.config.js or twig):
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
{{ mopa_bootstrap_include_js() }}
Twig Template Overrides:
{% extends 'MopaBootstrapBundle:Component:alert.html.twig' %}
{% block body %}Custom content{% endblock %}
Configuration Conflicts:
theme vs. bootstrap_theme).DependencyInjection/Configuration.php for the latest schema.Deprecated Methods:
mopa_bootstrap_include_assets() (deprecated in v3.4+).mopa_bootstrap_include_css()/mopa_bootstrap_include_js() instead.Symfony 6+ Asset Component:
{{ asset() }} may not work with bundle assets in Symfony 6+.asset component:
mopa_bootstrap:
assets:
base_url: '%env(APP_URL)%/bundles/mopabootstrap'
Check Loaded Assets:
{{ dump(mopa_bootstrap_include_css()) }}
Enable Debug Mode:
Clear Cache:
php bin/console cache:clear
Log Configuration:
$this->get('mopa_bootstrap.configuration')->getConfig();
Custom Components:
Mopa\Bundle\BootstrapBundle\Twig\Extension\BootstrapExtension.Asset Pipelines:
config/packages/mopa_bootstrap.yaml or via environment variables.Plugin Initialization:
mopa_bootstrap_javascript block in Twig.Theme Switching:
{% set theme = app.user.theme ?? 'default' %}
{{ mopa_bootstrap_include_css({'theme': 'themes/' ~ theme ~ '.css'}) }}
Symfony Messenger Integration:
{% for message in app.flashes('success') %}
{{ mopa_bootstrap_alert(message, 'success') }}
{% endfor %}
How can I help you explore Laravel packages today?