1
votes

I'd like to manage Twitter Bootstrap git repository using deps file in Symfony2. So i added these lines:

[TwitterBootstrap]
    git=https://github.com/twitter/bootstrap.git
    target=/twitter
    version=v2.0.3

and the repository is cloned into Symfony2\vendor\twitter\bootstrap.

Im' stuck ad this: how can i import the relevant css/js using assetic and how cssrewrite rule works when images are placed into Symfony2\vendor\twitter\bootstrap\img instead of Symfony2\app\Resources\public\img.

 {% stylesheets '????????????????' filter='cssrewrite' %}
     <link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
 {% endstylesheets %}
4

4 Answers

2
votes

have you tried using MopaBootstrapBundle which implements twitter bundle to symfony2? https://github.com/phiamo/MopaBootstrapBundle

I'm also working on implementing HTML5Boilerplate + TwitterBundle generated via http://Initializr.com on https://github.com/nysander/MopaBootstrapBundle/tree/initializr branch

2
votes

Here's how I compile Bootstrap's LESS to CSS:

{% block stylesheets %}
    {% stylesheets
        '../vendor/bootstrap/less/bootstrap.less'
        output='css/bootstrap.css'
    %}
        <link href="{{ asset_url }}" rel="stylesheet">
    {% endstylesheets %}
{% endblock %}

I've installed lessphp — you could use Node.js instead — as a vendor and activated it like this:

assetic:
    debug: %kernel.debug%
    use_controller: false
    filters:
        cssrewrite: ~
        lessphp:
            apply_to: "\.less$"
            file: %kernel.root_dir%/../vendor/lessphp/lessc.inc.php

As for the cssrewrite filter, you don't need it in this case. If you somehow get Bootstrap images to the web/img folder, it will work. I'm still looking for a neat solution.

0
votes

I got this to work by making a symbolic link to vendor/twitter-bootstrap in my web directory (if you don't, the images will never be reachable). But I don't remember using twitter-bootstrap images.

I don't import bootstrap in my twig templates, but in the less file of my project, like this:

@import "../../../twitter-bootstrap/less/bootstrap";

But I've had many headaches with this method. See this bug report I wrote: https://github.com/kriswallsmith/assetic/issues/202

0
votes

MopaBootstrapBundle seems more flexible as stated by @nysander.

If you want a raw implementation of twitter-bootstrap, without any helper, this repository aims to provide Twitter Bootstrap as an asset for Symfony by encapsulating it in a public folder : https://github.com/chasen/bootstrap