2

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)?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply. It's against best practices to put plugins inside a bundles and i don't really like idea to copy plugin assets in the web directory manually as it will be hard to manage and update. I just don't see any other options though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.