Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Laravel 'public' path for javascript file

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.

like image 785
dan2k3k4 Avatar asked May 14 '13 09:05

dan2k3k4


1 Answers

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>

...
like image 91
Jason Lewis Avatar answered Oct 26 '22 11:10

Jason Lewis