elao/theme-twitter-bootstrap-3-bundle
Symfony bundle providing a Twitter Bootstrap 3 theme for the Elao Theme Bundle. Includes form themes, Twig templates, and Twig helpers to quickly apply Bootstrap 3 styling across your Symfony app.
Installation
Add the bundle to your composer.json:
composer require elao/theme-twitter-bootstrap-3-bundle
Enable it in config/bundles.php:
Elao\Theme\TwitterBootstrap3Bundle\ElaoThemeTwitterBootstrap3Bundle::class => ['all' => true],
Basic Configuration
Override the default theme in app/config/config.yml:
elao_theme:
theme: "ElaoThemeTwitterBootstrap3Bundle::default"
First Use Case
Extend a base template (e.g., base.html.twig) to leverage Bootstrap 3 classes:
{% extends 'ElaoThemeTwitterBootstrap3Bundle::base.html.twig' %}
{% block body %}
<div class="container">
<h1 class="page-header">Welcome</h1>
<div class="alert alert-success">Bootstrap 3 is ready!</div>
</div>
{% endblock %}
ElaoThemeTwitterBootstrap3Bundle::* as parent templates (e.g., base.html.twig, layout.html.twig).{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('css/custom.css') }}">
{% endblock %}
{% form_theme form '_ElaoThemeTwitterBootstrap3Bundle:Form:bootstrap_3_layout.html.twig' %}
form_div_layout.html.twig) in your project’s Resources/views/Form/.{% block javascripts %}
{{ parent() }}
{{ encore_entry_link_tags('app') }} {# For Webpack Encore #}
{% endblock %}
resources/public/ to include custom Bootstrap extensions (e.g., bootstrap-custom.css).row, col-*) in Twig:
<div class="row">
<div class="col-md-6">Left Column</div>
<div class="col-md-6">Right Column</div>
</div>
<a href="{{ path('connect', {'service': 'github'}) }}" class="btn btn-primary">
Connect with GitHub
</a>
<div class="form-group">
{{ form_widget(form.file, {'attr': {'class': 'form-control'}}) }}
</div>
Deprecated Bundle
twig, symfony/form).Asset Conflicts
// webpack.config.js
Encore
.addEntry('app', './assets/app.js')
.enableSassLoader()
.copyFiles({
from: './node_modules/bootstrap/dist/css/bootstrap.min.css',
to: 'css/[name].[ext]'
});
Twig Template Caching
php bin/console cache:clear
Form Theme Paths
Resources/views/Form/ or configure custom paths in config.yml:
twig:
form_themes:
- '@ElaoThemeTwitterBootstrap3/Form/bootstrap_3_layout.html.twig'
- 'Form/bootstrap_extensions.html.twig'
bootstrap.min.css).Custom SCSS Variables Override Bootstrap variables by extending the bundle’s SCSS:
// assets/scss/custom.scss
@import "~bootstrap-sass/assets/stylesheets/bootstrap/scss/variables";
$btn-default-bg: #6c757d; // Customize default button color
@import "~bootstrap-sass/assets/stylesheets/bootstrap/scss/bootstrap";
New Components
Create reusable Twig components (e.g., components/card.html.twig):
{# Usage #}
{% include 'components/card.html.twig' with {
'title': 'Card Title',
'content': 'Card content here'
} %}
JavaScript Extensions Use Symfony’s asset system to add custom JS:
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('js/custom-bootstrap.js') }}"></script>
{% endblock %}
# config/packages/asset.yaml
assets:
version: 'unique_id' # Disable fingerprinting
<script src="{{ asset('js/bootstrap.min.js') }}" defer></script>
How can I help you explore Laravel packages today?