Symfony Unable to Generate a URL for Route to Stylesheet

Chadwick Meyer picture Chadwick Meyer · Feb 8, 2015 · Viewed 8k times · Source

I have two CSS files in the same folder, with identical access rights. When testing in the same Twig file, one CSS file generates a URL to the file and loads perfectly and one gives an error.

Error

An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "_assetic_a328b4c_0" as such route does not exist.") in @GutensiteStream/Stream35163.html.twig at line 19.

Files on Server

ls -al /var/www/core/cms/src/Templates/GutensiteAdminBundle/Resources/public/css
-rw-rw-r-- 1 chadwick developer  17K Feb  7 14:00 dashboard.css
-rw-rw-r-- 1 chadwick developer  49K Feb  6 16:00 site.css

Template with CSS that Loads

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

Template with CSS that does NOT Load

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

Linking to the File Directly Works

<link rel="stylesheet" href="/gutensite/v/2/0/bundles/templatesgutensiteadmin/css/dashboard.css">

Steps Taken

I have already cleared cache multiple times, via app/console cache:clear and via rm -rf app/cache/*. I use php app/console assets:install --symlink /var/www/core/web/gutensite/v/2/0/ to symlink the public files to the bundles, and of course they are accessible (as demonstrated via the direct link).

My Config.yml

assetic:
    #don't use dynamic links to assets, use full production paths
    use_controller: false

Answer

smcjones picture smcjones · Jun 30, 2017

When I ran into this error, the solution was quite simple:

When in doubt:

bin/console cache:clear

Assetic is looked for a cached version which doesn't exist. This could be for any number of reasons, but cache:clear seems like it should be the first stop.