如何在Silex中设置twig文件和资产文件(CSS,Js)之间的引用?

Before I start I want to say that I am new to working with this framework and some of its features I do not fully understand.

So, I have the following structure:

Desired assets folder location:

  • web
    • assets
      • css
        • file.css

Current twig views location:

  • src
    • App
      • views
        • file.html.twig

So the "web" and "src" are on the same level. Now how can I link the CSS for the "file.html.twig"? I also read the Silex cookbook (http://silex.sensiolabs.org/doc/cookbook/assets.html) but I don't quite understand where do I have to write every step presented there. Thank you.

The app.request.basepath is a link the base path of your application, e.g. the public (accessible) php file where you instanciate and run you Silex application.

Mine is an index.php in /web, so writing {{ app.request.basepath }}/assets/css/file.css is OK and leads to 'web/assets/css/file.css', but my guess is thaht you did not put your main index.php file in /web directory (maybe in a sub-directory). You should check that first.

I'm quite new to Silex as well so you should take my words with caution, but taking a look at it doesn't cost anything after all ;)