I want to use TwitterBootstrap in my Symfony2 bundle. Please give me a advise how to do that right way.
I use composer to install TwitterBootstrap into my vendor derectory (composer require twitter/bootstrap).
How to link css & js in to my twig template?
4
Answers
Thank you for the help.
For now I don`t want to use additional bundles or other thinks. I just want to connect css and js files to my template.
Solution I use for now is:
Install fia composer jquery and twitterbootstrap in vendor/components/jquery and vendor/twbs/bootstrap directories
In
config.yml
I create a named assets:It's important to create jQuery asset first. Assetic changes the paths to your assets, this will break any background images (or other paths) that uses relative paths, so I ned to add rule for the font files to make glyphicons work (find example here).
In the head section of
layout.html.twig
file I paste:All worked!
An easy way to integrate Bootstrap is to declare the stylesheet in the
base.html.twig
file :You can also use
asset
to load your stylesheet. Have a look to Templating with SymfonyAnother way would be to use the MopaBootstrapBundle.
With this Bundle you get a really great integration into Symfony, for example twig extensions and templates for use with Symfony Form component, so you don’t need to style everything by yourself.
As all knows Bootstrap is related to assets, and all third party bundles, or direct includes lookls ugly (mostly form
/vendor/
directory do not do this!). So better use Bower what created special for managing your asstes. You can configura it for install all assets to Symfony2web
directory and then useassets
in twig. Here is some links for documentation:Instalation guide
Configuration
Hope this will help to you 🙂