0

THIS link suggests that /app directory contains all configuration, templates (.html.twig files) and translations, and the /src directory contains PHP code.

However, HERE we can see that .css and .js files are loaded from /src/AppBundle/Resources/public directory and not /app/Resources/public directory. What is the best practice? How should I professionaly approach this problem, and where should I keep all the templates, .js and .css files?

  • u can keep all the css and js in `web` folder. – Hari Sep 13 '17 at 09:12
  • I am using assetic for assets management, and the question is about best practices and the proffesional approach. – Michał Śnieżko Sep 13 '17 at 09:14
  • There is no single answer. Most of this will come down to personal experience / preference. – Jonnix Sep 13 '17 at 09:17
  • so what's the problèm of using the assetic mangment !! you can use assetic and just set your stylesheets and js files under web/app/css web/app/js – famas23 Sep 13 '17 at 09:19
  • Well, if you are following modular approach which I think is a best practice, it gives you cleaner code and it helps implements single responsibility principle, you would put your assets in `/src/AppBundle/Resources/public` every bundle should be independent and have its own assets, which makes it easier to reuse. – teeyo Sep 13 '17 at 09:21

2 Answers2

0

I like to put css and javascript that serve for general purposes in /app/Resources/public and the ones specific to the concerned bundle in /src/YourBundleNameBundle/Resources/public. Like that when I want to see a code specific for a bundle I will just go to that bundle , when it's a general purpose code I would be sure that it's in the root. I have seen expert people doing it and it makes sense for me.

It's a matter of choice and there is no right and wrong answer.

zizoujab
  • 7,603
  • 8
  • 41
  • 72
0

the best practice is to put your css and js files in your bundle particularly in folder that you called "public" (yourBundle/Ressources/public/css/yourStyle.css) and make sure to run this command before

php bin/console assets:install

and To avoid typing this command each time, I recommend you make a link (a kind of shortcut), by adding the active parameter:

assets:install --symlink

So, the web /bundles/folderBundle actually points to src/yourBundle/Resources/public

On Windows, you must run the command prompt in administrator mode