Search code examples
symfonytwigdevelopment-environmentproduction-environmentassetic

Symfony2 Production CSS/JS includes throwing 404 (may be a parent issue)


I am writing a Bundle to theme a site we are developing. The other Bundles call on a Core bundle for templating via Twig, and this Themeing bundle warps that core bundle.

I have done this by implementing the getParent() method inside the theme bundle class to return the name of the core bundle, thus causing Symfony2 to look in the theme bundle (for basically ANY file) before looking in the Core bundle.

Now, this works great in Dev mode, however, when I try in Production Mode, and my CSS/JS files are combined into one, the resulting path resolves to a 404 page, and all styling is lost.

I have cleared both dev and production cache, as well as rm -rf'd the dev and prod directories. Calling php app/console assetic:dump --env=prod --no-debug returns:

$ php app/console assetic:dump --env=prod --no-debug
Dumping all prod assets.
Debug mode is off.

10:25:40 [file+] /webapps/xxxbundle/app/../web/css/f996955.css
10:25:46 [file+] /webapps/xxxbundle/app/../web/js/f307b3f.js
10:26:05 [file+] /webapps/xxxbundle/app/../web/css/55d26a0.css
10:26:05 [file+] /webapps/xxxbundle/app/../web/js/ccfc30e.js



  [RuntimeException]
  The source file "/webapps/xxxclient/app/../web/bundles/xxxbundle/js/modernizer.custom.96376.js"
  does not exist.



assetic:dump [--watch] [--force] [--period="..."] [write_to]

The web facing css and js dirs show:

$ ls web/css
55d26a0.css  f996955.css
$ ls web/js
f307b3f.js

The missing JS file is likely due to another bundle that isn't being used. The main issue is, the template is looking for:

<link rel="stylesheet" type="text/css" media="screen" href="/css/2a6fc23.css">
<script src="/js/adf6a7a.js"></script>

Neither of which exist. Any ideas or directions?

[[ EDIT ]]

On further review, even the assetic production cache references these files, and yet they are never created... why? ....

[[ TEMPLATES ]]

(Overwritten Template)

{% extends 'FrontBundle:Frame:base.html.twig' %}
{% block title %}{{ page.title }}{% endblock %}

{% block wrapper %}

    {# route: {{ route }} #}

    {{ rendered | raw }}

{% endblock %}

(Overwriting Template)

{% extends 'SkinBundle::layout.html.twig' %}

{# Site Name #}
{% block site_name %}
    {{ page.title }} | {{ parent() }}
{% endblock %}

Layout extends a base template which is just a shell of a site, in the process overwritting lets say CSS like:

{% extends 'FrontBundle:Frame:default.html.twig' %}
{# Stylesheets #}
{% block stylesheets %}
{# no execute {{ parent() }}#}
{% stylesheets
    filter='cssrewrite'
    'bundles/core/css/normalize.css'
    'bundles/skin/css/main.css'
    %}
        <link rel="stylesheet" type="text/css" media="screen" href="{{ asset_url }}">
    {% endstylesheets %}
{% endblock %}

Which is declared in the Base template as:

        {# Stylesheets #}
        {% block stylesheets %}
            {% stylesheets
                filter='cssrewrite'
                'bundles/core/css/normalize.css'
                'bundles/front/css/global.css'
                'bundles/page/css/page.css'
            %}
            <link rel="stylesheet" type="text/css" media="screen" href="{{ asset_url }}">
            {% endstylesheets %}
            <!-- Page -->
        {% endblock %}

These style-sheets are not needed, which is why I have parent() wrapped in comment tags. Removing the line entirely doesn't help.


Solution

  • Removing parent() did help, after a thorough clearing of the cache and rebuild.

    I will be making a bug ticket here soon, as for some reason having parent() inside of a comment ({# ... #}) was breaking the generation, even though nothing inside of {# ... #} should be parsed, or indeed even considered, by the template compiler.

    Tricky bug.