This bundle requires Symfony 2.1+
In order to use this bundle you have to install bower
- Download SpBowerBundle using composer
- Enable the Bundle
- Configure the bundle
- Installing bower dependencies
- Use the installed assets in your templates
- Add composer scripts for automatic update of dependencies
- Installing dependencies on every cache warmup
Ask composer to add SpBowerBundle in your composer.json and to download it by running the command:
$ php composer.phar require sp/bower-bundle
Composer will install the bundle to your project's vendor/sp
directory.
Enable the bundle in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Sp\BowerBundle\SpBowerBundle(),
);
}
Enable bower dependency management for your bundles in the config.yml
file.
# app/config/config.yml
sp_bower:
bundles:
YourBundle: ~
Place your bower.json
in the config directory, the default value for the config dir is $yourBundle/Resources/config/bower
.
{
"name": "your-bundle-name",
"dependencies": {
"jquery": "~1.8.2"
}
}
Now run the command app/console sp:bower:install
to install all the necessary
dependencies in the asset directory $yourBundle/Resources/public
.
This bundle registers all installed bower assets automatically for you.
Lets say you have the following dependencies defined
# AcmeDemoBundle/Resources/config/bower/bower.json
{
"name": "acme-demo-bundle",
"dependencies": {
"bootstrap": "latest"
}
}
then you can use them in your templates (or wherever you need them) like this
{% javascripts
"@bootstrap_js" %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% stylesheets
"@bootstrap_css" %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
Note:
Since asset names in the AsseticLibrary can not contain
.
or-
characters, they will be converted to a_
. So the css files from "font-awesome" must be referenced with "font_awesome_css".
Note:
If you don't want this bundle to automatically register the assets, you can disable this behavior by setting
assetic
to false
Warning:
Your site may be slowed down if you enabled
use_controller
in the assetic bundle andassetic
in this bundle.
{
"scripts": {
"post-install-cmd": [
"Sp\\BowerBundle\\Composer\\ScriptHandler::bowerInstall"
],
"post-update-cmd": [
"Sp\\BowerBundle\\Composer\\ScriptHandler::bowerInstall"
]
}
}
If you want to install/update all bower dependencies during the warmup, you must set install_on_warmup
to true
# app/config/config.yml
sp_bower:
install_on_warmup: true