Hello Friends,
If you are new in Symfony and looking to get location to save your js, css or image files, please review this blog. We have many ways to save the public files in symfony here we are describing two different ways to save these public files:
Way 1 :: In the general practice programmer usually save these public files in the resources folder under their bundle. First of all you need to create css, js images folder under Resources folder now you can define your public files in Resources folder in your bundle like I have a bundle named My and we will save my js file as below:
Step One Path ::
projectname/src/My/BlogBundle/Resources/js/myassets.js
projectname/src/My/BlogBundle/Resources/css/myassets.css
projectname/src/My/BlogBundle/Resources/images/myassets.jpg
//Code to fetch this file on twig(View file)
<script src="{{ asset('MyBlogBundle/Resources/js/myassets.js') }}"></script>
<link rel="stylesheet" href="{{ asset('MyBlogBundle/Resources/css/myassets.css') }}" />
<img src="{{ asset('MyBlogBundle/Resources/images/myassets.jpg') }}">
Way 2 :: This is the idle practice to save public files(css, js, images) in "web" folder. You need to create css, js, images folder under yourproject/web.
Step Two Path ::
projectname/web/js/myassets.js
projectname/web/css/myassets.css
projectname/web/images/myassets.jpg
//Code to fetch this file on twig(View file)
<script src="{{ asset('MyBlogBundle/Resources/js/myassets.js') }}"></script>
<link rel="stylesheet" href="{{ asset('MyBlogBundle/Resources/css/myassets.css') }}" />
<img src="{{ asset('MyBlogBundle/Resources/images/myassets.jpg') }}">
Thanks
0 Comment(s)