New in Symfony 2.6: Bootstrap form theme
October 6, 2014 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
Bootstrap is the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web. Bootstrap is so widely used that it has become the de facto standard for frontend development. That's why Symfony 2.6 will include a new form theme designed for Bootstrap 3.
The new form theme comes in two flavors: normal layout and horizontal layout. To apply this new theme to all the forms of your application, use the following configuration:
1 2 3 4 5
# app/config/config.yml
twig:
form:
resources: ['bootstrap_3_layout.html.twig']
# resources: ['bootstrap_3_horizontal_layout.html.twig']
To apply this theme only for some forms, add the following instruction at the top of the Twig template where the form is defined:
1 2
{% form_theme form 'bootstrap_3_layout.html.twig' %}
{# {% form_theme form 'bootstrap_3_horizontal_layout.html.twig' %} #}
The new theme defines styles for all types of form controls, as shown in the following image:
As you probably guessed, this new feature is part of the Symfony DX initiative. We believe that having a built-in Bootstrap theme will save you lots of hours of tedious and repetitive work.
Although this pull request just adds two tiny Twig templates, it took eight months to get merged. In fact, this was the most commented pull request in Symfony's history (196 comments at the time of writing this post) and provoked some lively discussions between proponents and opponents of it.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
We'll add a UI-Kit theme when that project achieves the same number of stars on GitHub as Bootstrap. Right now: Bootstrap = 72,509 GitHub stars and UI-Kit = 3,489 stars.
Foundation has 18.2K stars, is that enough?
Jquery, 32K stars. Time to remove Sfjs and use jQuery instead?
Html5 boilerplate, 27K stars.
Answering your questions:
> Foundation has 18.2K stars, is that enough?
No, it's not enough. Bootstrap has more than 80,000 stars (72,515 for the LESS version and 7,493 for the SASS version)
> Jquery, 32K stars. Time to remove Sfjs and use jQuery instead?
I wish they would consider that. jQuery is the exact same case as Bootstrap. It's not just popular, it's the standard.
> Html5 boilerplate, 27K stars.
I think it's irrelevant because Symfony includes just a few HTML pages.
I think adding in jQuery would also be a good idea as it is just as popular (if not more so) than bootstrap.
Thanx a lot !
Could be nice to have an implement for menu and pager, like mopa-bootstrap does.
Thanks.
Thanks