0

I found how to reference an asset file on a Twig template here: How to include CSS file in Symfony 2 and Twig?

It says I should include the bundle folder in the path like this example: {{ asset('bundles/mybundle/css/main.css') }}

This solution is not reliable for me because I have many website templates with extensive asset file references (JS, CSS, Images) that I need to convert into Twig template and its hard for me to replace all asset paths with a full path like I mentioned in the example. At least it can be easier if I can use it like this: {{ asset('css/main.css') }}

Can anyone please help me in this issue ? Thanks to everyone.

Community
  • 1
  • 1
Elias
  • 449
  • 4
  • 9

2 Answers2

2

The news best practices recommended by Symfony are now to regroup the assets of your app in the web/ folder, you loose a bit of the re usability of your code but you get rid of a lot of suffering in your asset management.

This way you will be "able" (without thinking you are doing some dirty developement ;) ) to store your CSS in the web/css/ folder you made and then call them with

{{ asset('css/main.css') }}

http://symfony.com/doc/current/best_practices/web-assets.html

"Best Practice :

Store your assets in the web/ directory."

Community
  • 1
  • 1
Florent Destremau
  • 653
  • 1
  • 5
  • 24
1

You can include all css in a folder like this:

{% stylesheets 'bundles/main/js/lightbox/css/*' filter='cssrewrite' %}
    <link href="{{ asset_url }}" rel="stylesheet" type="text/css" />
{% endstylesheets %}
Andrei Stanca
  • 908
  • 2
  • 11
  • 26
  • Thanks, this helps, but I had to put all my resources under /web folder instead, because with the following method I should include all CSS and JS files I have, thing I shouldn't do – Elias Jun 25 '13 at 10:04