I'm using symfony framework 3 to develop a web application. I need to add boostrap's functionality to my application. I installed bootstrap using the below command. (I'm using composer.)
composer require twbs/bootstrap
It installs bootstrap to the application's vendor folder. More specifically vendor\twbs\bootstrap
.
I need to attach bootstrap's css
and js
files in the application's twig templates (located in app\Resources\views
) as assets.
e.g.:
<link href="{{ asset('css/bootstrap.css') }}" rel="stylesheet" />
But assets only work with files located in the web (web\bundles\framework
) folder. I can copy those .css
and .js
files from the vendor folder to web folder manually to make this work but there should be a proper way to do it (i.e.: to add assets). e.g.: A command with bin/console
?
Any help is appreciated.
The suggested approach changed since Symfony version 4: Webpack Encore is used with npm / yarn for bundling the CSS and JavaScript resources, where the Bootstrap framework can be included.
Start by installing Encore and follow with the Bootstrap-specific documentation. In summary, the following commands have to be performed:
From this link https://coderwall.com/p/cx1ztw/bootstrap-3-in-symfony-2-with-composer-and-no-extra-bundles (and changing
twitter
fortwbs
) this is what I have in myconfig.yml
:I do have other dependencies in my
composer.json
likejsqueeze
for example, or Leafo's scss processor, amongjquery
and more. I have this in my composer file:I then use it like this for the css:
and for the javascripts, place
jquery
first:I then use
bin/console assetic:dump
to compile all my assets.Hope to help!
Since Symfony v2.6 includes a new form theme designed for Bootstrap 3 oficial documentation
The Symfony Best Practies gives the answer for this Problem: http://symfony.com/doc/current/best_practices/web-assets.html
In our project we use grunt to build and concat those files into the web-folder.
As an alternative solution, the symlinks could be created automatically upon packages update. For example, in
composer.json
add new command in"post-update-cmd"
:It looks like that this no longer works in Symfony3.
In Symfony3 the following should work: