0
votes

I'm new to Symfony (2.4) and having trouble understanding how Assetic serves assets through the app instead of off the file system for development.

In particular, I'm trying to get the BrainCrafted Bootstrap Bundle setup so that I don't have to dump my assets for it to work on development.

In my base template file, I have:

<link href="{{ asset('/css/bootstrap.css') }}" rel="stylesheet" media="screen">

When I render a page using the app_dev.php, the path does not change and still tries to load it via /css/bootstrap.css, which does not exist.

My assetic setting for "use_controller" is set to true.

However, if I include a stylesheet like this:

{% stylesheets '@MyCustomBundle/Resources/public/css/*' %}
  <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

Then the URL to the stylesheet is properly rooted with "app_dev.php".

Why doesn't the main asset twig function prepend app_dev.php?

3

3 Answers

1
votes

BootstrapBundle configures Assetic using config.yml. You need to dump the assets using php app/console assetic:dump to generate the CSS files.

If you want to configure your stylesheets inside your Twig template you should use stylesheets (as mentioned by Dovydas Bartkevičius) and if you want to configure your stylesheets in your config.yml you have to generate the static CSS using php app/console assetic:dump and use assets to include the static files in your template.

BootstrapBundle configures Assetic using config.yml so you have to dump the assets. While developing you can also use php app/console assetic:dump --watch to generate the CSS every time the source changes.

0
votes

{{ asset }} function just adds a path to the assets folder of the project. It seems that your assets are in the bundle's directory therefore they are not public and cannot be reached.

http://symfony.com/doc/current/book/templating.html#linking-to-assets

{% stylesheets %} and {% javascripts %} actually takes asset files from your bundles, applies filters if present (compression, etc) and serves them at request through the controller.

You can dump asset files with command line API php app/console assetic:dump.

http://symfony.com/doc/current/cookbook/assetic/asset_management.html#dumping-asset-files

0
votes

If you pass an absolute path to the asset function then it will return the argument without changing it at all.