2

Each bundle has it's own public directory to store assets (css/js/images).

Now what is the best place for assets used in app\Resources\views\base.htl.twg?

How dose Symfony understand to populate them to public?

Mohammad Ali Akbari
  • 10,345
  • 11
  • 44
  • 62

2 Answers2

2

usually the assets of templates available in the app/Resources/view directory(like base.html.twig) are placed directly in a subdirectory of the web root like web/includes/css/main.css and called with asset('includes/css/main.css').

If you don't like it, you can easily create your own bundle to store the app assets.

Marino Di Clemente
  • 3,120
  • 1
  • 23
  • 24
  • Can I store assets in `app/Resources/public`? if yes, how? – Mohammad Ali Akbari Nov 03 '12 at 09:47
  • No you can't, the directory app/Resources/public is not mapped in the web directory. You need to put your assets in web directory – Marino Di Clemente Nov 03 '12 at 09:56
  • With assetic you can:) Look there http://stackoverflow.com/questions/11192568/symfony2-how-to-share-js-libs-and-css-between-bundles, http://stackoverflow.com/questions/6903473/where-do-symfony2-shared-css-and-js-assets-go-best-practice-wise – Marino Di Clemente Nov 03 '12 at 10:00
  • I tell you more about. You can get your assets from anywhere with assetic, but is a overoptimization in the initial phase of a project, I usually put my development assets in the /web directory and then move them inside their bundle or leave where they are. Put static files in /app/Resource/public or in /web means exactly the same thing with the difference that files in /web directory are directly accessibile, intead files in app/Resources/public need to be mapped/linked in some way – Marino Di Clemente Nov 03 '12 at 10:12
  • excuse me for this question: what is deference between `assetic-bundle` in `vendors/symfony` with `github.com/kriswallsmith/assetic` – Mohammad Ali Akbari Nov 03 '12 at 10:25
  • asseticbundle is a bridge between assetic features and symfony2. In simple terms it allows you to work with Bundle's syntax, to call the assetic:dump command and to configure assetic in app/config/config.yml, look there http://symfony.com/doc/2.0/cookbook/assetic/asset_management.html . Without it assetic use in symfony would be equally possible but more harder – Marino Di Clemente Nov 03 '12 at 10:40
2

I suggest you to create a DesignBundle to store all base template and assets. This method permit you to share your configuration with other application.

sensorario
  • 20,262
  • 30
  • 97
  • 159
  • So I should select one of these ways: 1- Place assets on web directory. 2- Create a bundle to store shared assets. am I true? – Mohammad Ali Akbari Nov 04 '12 at 10:11
  • Yes. But not exist the right way: try both and choose the better for you. – sensorario Nov 04 '12 at 11:58
  • 1
    My solution permit you to get all your layout and all your design separated. You can extend from YourCompany/DesignBundle/Category/YouDesignName.html.twig for example: Acme/DesignBundle/ColumnsLayout/ThreeColumn.html.twig, Acme/DesignBundle/ColumnsLayout/TwoColumn.html.twig, Acme/DesignBundle/Templates/User.html.twig, ... and so on. – sensorario Nov 04 '12 at 12:05