konrad konrad - 1 year ago 133
PHP Question

How to use vendor bundles resources in Symfony2

I know this is a very basic question and I'm pretty puzzled that I couldn't find a good answer for that.

Let's say I installed twbs/bootstrap package with Composer, so it lands in its proper vendor/twbs/bootstrap/ directory. Now, what do I need to do to make it actually useful, i.e. copy the bootstrap/dist/ folder containing css/js files to the web/ folder?

Is there any (semi)intelligent 'Symfonic' way to handle this or should I a) copy/update the needed files manually, b) setup e.g. a grunt copy task for that?

I'm using Symfony 2.6 on Windows 7 if that matters.

Answer Source

You can only install repositories that are symfony2 bundles. In case of https://github.com/twbs/bootstrap, it isn't.

You'll have to find another bundle for symfony2 doing the same, like this one for instance: https://github.com/braincrafted/bootstrap-bundle

And as explained in their doc like almost if every bundle doc, here is how you install this bundle (the procedure is the same for the majority of them):


BraincraftedBootstrapBundle should be installed using Composer:

    "require": {
        "braincrafted/bootstrap-bundle": "~2.0"

part about Bootstrap and jQuery sniped, not directly relevant to hoiw install a bundle, go read it in the doc.

Then add the bundle to your AppKernel.php:

# app/AppKernel.php

class AppKernel extends Kernel
    public function registerBundles()
        $bundles = array(
            // ...
            new Braincrafted\Bundle\BootstrapBundle\BraincraftedBootstrapBundle(),
        // ...

BraincraftedBootstrapBundle highly recommends you to use Assetic for managing assets. If you do use Assetic for managing your assets, you should now run the dump command.

php app/console assetic:dump
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download