Select2 Bundle for Symfony2
Current Version
Select2 3.4.2 (31)
Installation
Add bundle to your composer.json file
// composer.json
{
"require": {
// ...
"fergardi/select2-bundle": "dev-master"
}
}
Add bundle to your application kernel
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Fergardi\Select2Bundle\FergardiSelect2Bundle(),
// ...
);
}
Download the bundle using Composer
$ php composer.phar update fergardi/select2-bundle
Install assets
Given your server's public directory is named "web", install the public vendor resources
$ php app/console assets:install web
Optionally, use the --symlink attribute to create links rather than copies of the resources
$ php app/console assets:install --symlink web
Notes: All the urls of the original routes have been changed to '../images/*' due to Bundle package requirements.
Usage
Once you have imported all the resources to the vendor folder, you can self-import the JS into your Symfony project as usual with:
{# block js #}
{% block javascripts %}
{% javascripts filter='cssrewrite' output='js/base.js'
...
'@FergardiSelect2Bundle/Resources/public/js/select2.min.js'
'@FergardiSelect2Bundle/Resources/public/js/select2_locale_XX.js'
...
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
And with the CSS as well using with:
{# block css #}
{% block stylesheets %}
{% stylesheets filter='cssrewrite' output='css/base.css'
...
'bundles/fergardiselect2/css/select2.css'
...
%}
<link rel="stylesheet" type="text/css" media="screen" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}
Note: See https://github.com/kriswallsmith/assetic/issues/53 for known limitations of assetic with CSS referencing.
Licenses
I do not own Select2 files at all, I'm just providing a Bundle package to easy-install them all. Refer to the source code of the included files from Select2 for license information.