sameddin/bootstrap-bundle
Bootstrap Bundle integrates Bootstrap into PHP applications, bundling frontend assets and offering convenient helpers for building responsive, styled interfaces. It reduces setup work so you can focus on features instead of wiring CSS and JavaScript.
Install the bundle with Composer (this is a Symfony bundle, not a Laravel package — see Gotchas):
composer require sameddin/bootstrap-bundle
Register it in config/bundles.php (or AppKernel.php on Symfony 2/3):
// config/bundles.php
return [
// ...
Elnur\BootstrapBundle\ElnurBootstrapBundle::class => ['all' => true],
];
Enable the Twig form theme in config/packages/twig.yaml:
twig:
form_themes:
- '@ElnurBootstrap/Form/bootstrap_3_layout.html.twig'
First use case: render any existing Symfony form and get Bootstrap 3 form-group / control-label / form-control markup without touching the form type:
{{ form_start(form, {attr: {class: 'form-horizontal'}}) }}
{{ form_row(form.email) }}
{{ form_row(form.password) }}
<button class="btn btn-primary">Save</button>
{{ form_end(form) }}
Look first at the bundle's Resources/views/Form/ directory — the twig layouts there define every widget and are the source of truth for what HTML you'll get.
Global theme. Setting form_themes in Twig config applies the Bootstrap markup to every form. This is the normal path for an app that is Bootstrap-3 end to end.
Per-form override. For a single screen, use the form_theme tag at the top of the template, which wins over the global theme:
{% form_theme form '@ElnurBootstrap/Form/bootstrap_3_horizontal_layout.html.twig' %}
Form type extensions for layout props. The bundle ships type extensions that let you pass Bootstrap-specific options straight into form_row/add():
$builder->add('search', SearchType::class, [
'input_group' => [
'prepend' => ['icon' => 'search'],
'append' => ['button' => 'Go'],
],
]);
Static controls and inline checkboxes. Use the bundled types (StaticControlType, ChoiceType with inline) rather than hand-writing <p class="form-control-static">.
Custom widgets. Compose buttons/button groups with the bundle's ButtonType/ButtonGroupType so classes stay consistent across forms.
Workflow tip. Because it plugs into Symfony's form rendering pipeline, the fastest integration is: install → set the global theme → render an existing form → fix only the fields that need extra layout options. Don't rewrite templates wholesale.
laravelcollective/html-style helpers.form-group, col-sm-*, input-lg, form-control-static, btn-default) do not survive a jump to Bootstrap 4/5. Expect breakage if you upgrade your CSS.choices_as_values, old Twig APIs). Pin the Symfony version or vendor a fork.form_themes entries are tried in order; your global theme must come before any custom theme that extends it, otherwise widgets fall back to Symfony's default form_div_layout.form_theme is actually applied — use bin/console debug:twig to confirm the bundle's template path is registered, and inspect the resolved theme with a dump(form) / Twig dump() on form.vars.form_row with an option the theme doesn't handle (e.g., a newer help option), it may silently render nothing. Grep the layout template for the block name before relying on it.bootstrap_3_layout.html.twig and {% use %}-ing it, then redefining e.g. {% block form_row %}. That's the safe way to customize without editing vendor files.attr; passing 'attr' => ['class' => 'form-control'] will be merged with — not replace — the theme's classes, so duplicate classes can appear.How can I help you explore Laravel packages today?