2

I am creating a bundle that requires a 3rd party js file. According to the documentation:

http://symfony.com/doc/current/cookbook/bundles/best_practices.html#vendors

Bundles should not contain 3rd party code. Since the bundle is only used in one part of the site I dont want to include it in my base template file - I want to call it from the twig file, but I am running into a problem there.

All of the demos for including js seem to reference a bundle name, but I have placed my js in app/Resources/public/js

If I use:

{% javascripts 
    "public/js/jquery.fileupload.js" %}
    <script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}

It looks in the web directory. Is there any way to use the app dir where all of my other js files live? I'm trying to follow best practices where feasible, but I would really like to keep my js in one place for simplicity, thanks for reading!

Joe Riggs
  • 1,312
  • 4
  • 23
  • 48
  • see if this helps http://stackoverflow.com/questions/11192568/symfony2-how-to-share-js-libs-and-css-between-bundles – saamorim Nov 21 '13 at 15:50
  • nope I get a 500 response. I think it's mangling the path something like ../app/..web/..app which isnt finding the file – Joe Riggs Nov 21 '13 at 16:06

2 Answers2

0

You can do it by symlinking the Public directory in app/Resources. It's kinda messy but it should work.

On *nix, you could run:

cd ROOT_TO_YOUR_PROJECT/web/bundles
ln -s ../../app/Resources/Public common 

Basically, you are creating common symlink that points to you Public directory.

Then:

{% javascripts 
    "bundles/common/js/jquery.fileupload.js" %}
    <script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}
Jovan Perovic
  • 19,846
  • 5
  • 44
  • 85
  • 1
    Thanks for the response. Seems kinda like a workaround. Maybe the fact the there isnt any easy way to do this means that I should just a create a Layout or Template Bundle and house all of my assets there. Then I can access those files the 'Symfony' way. Thanks again! – Joe Riggs Nov 21 '13 at 17:50
-1

This sounds related to a bug in Symfony's assetic. When you run app/console assetic:dump it doesn't base itself in the web folder, it uses the current folder. See: https://github.com/kriswallsmith/assetic/issues/202

rjmunro
  • 27,203
  • 20
  • 110
  • 132