9

I'm unsure how I can get something equivalent to: path('public') to work in a Javascript file?

I basically just need the path to the public folder for displaying some images from my JS file.

dan2k3k4
  • 1,388
  • 2
  • 23
  • 48
  • I always just do /public and it works. I'm not sure if there's a more modular way to do it. Sorry that I'm not more help. – skcin7 May 14 '13 at 09:49

1 Answers1

11

You could opt to create a variable in JavaScripts global namespace in the head of your document and use PHP to echo out the public path.

<head>
    <script>
        var public_path = '{{ path('public') }}';
    </script>

...
Jason Lewis
  • 18,537
  • 4
  • 61
  • 64