1

I'm looking for including .css ans .js files using Assetic with Symfony. The issue is the browser fails to load these files.

{% block stylesheets %}
      {% stylesheets '@MUSCoreBundle/Resources/public/css/*' filter='cssrewrite' %} 
      <link rel="stylesheet" href="{{ asset_url }}"/>
  {% endstylesheets %}
{% endblock %}


{% block javascripts %}
  {% javascripts '@MUSCoreBundle/Resources/public/js/*' %}
      <script type="text/javascript" src="{{ asset_url }}"></script>
  {% endjavascripts %}
{% endblock %}

sources

Browser console

I wrote the good path to my files.

What am i doing wrong ?

The solution : you have to create the .css and .js files inside the folder CSS. It seems the server can't acess these files if you had copied and pasted them from an other location.

2
  • Try to add @ before your path: @MUSCoreBundle/Resources/public/font-awesome/css/font-awesome.min.css Commented Mar 9, 2015 at 11:18
  • @chapay I tried to add @ : An exception has been thrown during the compilation of a template ("Unable to find file "@MUSCoreBundle/Resources/public/font-awesome/css/font-awesome.min.css".") in "::layout.html.twig". Commented Mar 9, 2015 at 13:09

1 Answer 1

2

If there is a css folder and i want to load all files in that folder then i use this method

{% block stylesheets %}
    {% stylesheets 'bundles/yourbundle/css/*' filter='cssrewrite' %}
    <link rel="stylesheet" href="{{ asset_url }}"/>
    {% endstylesheets %}
{% endblock %}

You can also load specific files forexample

{% block javascripts %}
    {% javascripts
    '@yourBundle/Resources/public/js/jquery.min.js'
    '@yourBundle/Resources/public/js/flat-ui.js'
    '@yourBundle/Resources/public/js/application.js'
     %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}
{% endblock %}

IMPORTANT

Remember to run the following commands when you change something in asset or add new asset

php app/console assets:install
php app/console assetic:dump --env=prod --no-debug 

You can read more about these in symfony asset documentation

Sign up to request clarification or add additional context in comments.

4 Comments

I edited my post : I followed your first example. Now as you see the browser fails to load the .css and .js files. I also tried to run the command ̀ php app/console assetic:dump --env=prod --no-debug ` and the console displays The source file "/home/isen/public_html/Symfony/app/../web/MUSCoreBundle/Resources/public/css/pa‌​ge_in scription.css" does not exist.
I think you are not pointing it right. Go to the web folder, then bundle folder, then open CSS or js folder to check if files exist.
can you also confirm if your asset link looks like this {% stylesheets 'bundles/MUSCore/css/*' filter='cssrewrite' %} and NOT {% stylesheets '@MUSCoreBundle/Resources/public/css/*' filter='cssrewrite' %}
I found the solution : you have to create the .css and .js files inside the folder CSS. It seems the server can't acess these files if you had copied and pasted them from an other location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.