Slava Fomin II
Slava Fomin II

Reputation: 28621

Add jquery plugin to Symfony 2.1 project

How can i add some jQuery plugin to a Symfony 2.1 project?

I install all frontend assets with the composer so all plugins are stored in the Symfony/vendor directory.

I can specify JS-file to load in a template like this:

{% javascripts filter='?yui_js' output='js/compiled/plugins.js'
    '%kernel.root_dir%/../vendor/author/plugin1/plugin.js'
    '%kernel.root_dir%/../vendor/author/plugin2/plugin.js'
    '%kernel.root_dir%/../vendor/author/plugin3/plugin.js'
%}

And after calling:

php ./app/console assetic:dump ...

All specified files will be compiled and placed under the Symfony/web directory.

But what if some plugin requires more than just a single JS or CSS file? What if it needs to load some images, styles or scripts dynamically from inside a plugin directory (which is out of web-server's document root)?

Upvotes: 2

Views: 2490

Answers (1)

Ville Mattila
Ville Mattila

Reputation: 1343

Unfortunately this is a slight problem with Assetic. Combining the css files to one with assetic:dump can break the plugin's internal directory structure. It is pretty much up to the plugin's own architecture how it survives from the asset dumping.

One option is to use assets:install command that copies or symlinks the asset files from Bundle/Resources/public/ folder to web/bundles/ directory.

What I usually do is to place the external library files (css, js and images) directly under web/ in proper subfolders. When css and js files are combined and placed to the web root (with assetic:dump) all the plugin files are found from the proper subfolders. This method works also when working in CDN environment. However, this is not the most elegant solution and it slightly violates the idea that all Bundles (or plugins) should stay separated from each other.

Upvotes: 2

Related Questions