Symfony2, where to put css, javascript, images
Asked Answered
F

4

10

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

Fulbert answered 6/8, 2013 at 4:43 Comment(1)
See excellent answer here: #9501073. This has worked well for us.Imeldaimelida
H
12

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.

Hydroxide answered 6/8, 2013 at 7:9 Comment(0)
D
2

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') ?>
Downbow answered 15/4, 2015 at 14:16 Comment(0)
A
0

We put them in web/assets/[css|img|js|fonts|less|xml|...]

Aureolin answered 6/8, 2013 at 5:15 Comment(0)
E
0

If your css/js file is used only within your bundle, placing them in bundle resources is OK. Otherwise placing onto the public folder if it's used by many bundles

Endocardium answered 6/8, 2013 at 6:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.