Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2, where to put css, javascript, images

I'm a beginner at Symfony2, and I have some problems about putting resource like css, js, images... I just read this document how to use Assetic But I can't figure out what is the best way to put my assets. That article show me that I should put js files inside my Bundle, but put css files in /web/public/css (out side the Bundle). That's complicated and inconvenience. Can somebody show me ? Thanks

like image 273
Vien Le Mai Avatar asked Aug 06 '13 04:08

Vien Le Mai


2 Answers

You can put them into the *Bundle/Resources/public/, then run

$ php app/console assets:install --symlink

This will create a symbolic link with the bundle name in your web/bundles/ linking to the existing bundles' public folders. If you want a simpler path in your html (or mainly css) code you can create a symbolic link directly in your web folder.

like image 177
mikayel ghazaryan Avatar answered Nov 12 '22 14:11

mikayel ghazaryan


If you use the Accepted Answer

app/console assets:install web --symlink

When you include your files (css,js,image) you need to change the PATH like that in TWIG :

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

And in PHP :

<?php echo $view['assets']->getUrl('bundles/myBundle/img/logo.png') ?>
like image 2
CDO Avatar answered Nov 12 '22 15:11

CDO