Search code examples
symfonylibrariesassetic

What is the best way to use front libraries in symfony2


For example, if I want to use Twitter bootstrap 3 in a Symfony 2 project without using a bundle (and of course, without using a CDN). What is the best way to do that ?

There is a better solution than using an output attribute of stylesheet tag in Twig ?


Solution

  • For my project, I decided to use bower frontend package manager. I can specify required libs(bower.json):

    "dependencies": {
        "bootstrap": "~3.3.4",
        "font-awesome": "~4.3.0",
        "jquery" : "~2.1",
        "markup" : "https://github.com/adammark/Markup.js.git",
        "js.class" : "~2.5",
        "bootstrap-select" : "~1.6"
    }
    

    And directory to download(.bowerrc):

    {
      "directory" : "web/components"
    }
    

    And $ bower install will download your dependencies to specified folder. In template files I link such resources directly:

    <link rel="stylesheet" href="{{ asset('components/bootstrap/dist/css/bootstrap.min.css') }}" media="screen">