What is the correct way to add bootstrap to a symfony app?

后端 未结 6 745
灰色年华
灰色年华 2021-02-13 13:48

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 usin

6条回答
  •  甜味超标
    2021-02-13 14:27

    From this link https://coderwall.com/p/cx1ztw/bootstrap-3-in-symfony-2-with-composer-and-no-extra-bundles (and changing twitterfor twbs) this is what I have in my config.yml:

    assetic:
        debug:          '%kernel.debug%'
        use_controller: '%kernel.debug%'
        filters:
            cssrewrite: ~
            jsqueeze: ~
            scssphp:
                formatter: 'Leafo\ScssPhp\Formatter\Compressed'
        assets:
            jquery:
                inputs:
                    - %kernel.root_dir%/../vendor/components/jquery/jquery.js
            bootstrap_js:
                inputs:
                    - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/js/bootstrap.js
            bootstrap_css:
                inputs:
                    - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/css/bootstrap.css
                    - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/css/bootstrap-theme.css
                filters: [ cssrewrite ]
            bootstrap_glyphicons_ttf:
                inputs:
                    - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf
                output: "fonts/glyphicons-halflings-regular.ttf"
            bootstrap_glyphicons_eot:
                inputs:
                    - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/fonts/glyphicons-halflings-regular.eot
                output: "fonts/glyphicons-halflings-regular.eot"
            bootstrap_glyphicons_svg:
                inputs:
                    - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/fonts/glyphicons-halflings-regular.svg
                output: "fonts/glyphicons-halflings-regular.svg"
            bootstrap_glyphicons_woff:
                inputs:
                    - %kernel.root_dir%/../vendor/twbs/bootstrap/dist/fonts/glyphicons-halflings-regular.woff
                output: "fonts/glyphicons-halflings-regular.woff"
    

    I do have other dependencies in my composer.json like jsqueeze for example, or Leafo's scss processor, among jquery and more. I have this in my composer file:

        "components/font-awesome": "^4.7",
        "components/jquery": "^3.1"
        "leafo/scssphp": "^0.6.7",
        "patchwork/jsqueeze": "^2.0",
        "symfony/assetic-bundle": "^2.8",
        "twbs/bootstrap": "^3.3",
    

    I then use it like this for the css:

    {% stylesheets
        '@bootstrap_css'
        'my/other/scss_file1.scss'
        'my/other/scss_file2.scss'
    
        filter='scssphp,cssrewrite'
        output='css/HelloTrip.css' %}
    
        
    
    {% endstylesheets %}
    

    and for the javascripts, place jquery first:

    {% javascripts
        '@jquery'
        '@bootstrap_js'
        'my/other/js_file1.js'
        'my/other/js_file2.js'
    
        filter='?jsqueeze'
        output='js/HelloTrip.js' %}
    
        
    
    {% endjavascripts %}
    

    I then use bin/console assetic:dump to compile all my assets.

    Hope to help!

提交回复
热议问题