symfony2 assetic path suddenly escaped in symfony2.7

134 views Asked by At

I'm upgrading my code from symfony2.6 to symfony2.7 and run into a weird thing with my assets.

example codes are a bit shortened.

I'm using this to set my css files in a head.html.twig.

{% stylesheets '@MyAwesomeBundle/Resources/subfolder*.less' %}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}

This in my config file:

# Assetic Configuration
assetic:
    debug:          %kernel.debug%
    bundles:
      - MyAwesomeBundle
    node:       %path.nodejs%
    node_paths: [ %path.node_modules% ]
    filters:
        less:
            apply_to:   "\.less$"

The less files are compiled fine. The problem is the resulting url in the webpage, which looks like this:

<link rel="stylesheet" href="\2F css\2F 36f682f\5F bootstrap\5F 1\2E css"/>

When I add a |raw filter to the twig-file the path is just fine.

{# twig #}
<link rel="stylesheet" href="{{ asset_url|raw }}"/>

{# resulting html #}
<link rel="stylesheet" href="/css/36f682f_bootstrap_1.css"/>

Any idea how to remedy this? I hate to go through all my twig files and add the raw-filter.

I've looked at all dependencies I'm pulling in with composer, they appear to be at the latest stable versions (no dev-versions being used).

2

There are 2 answers

0
DoppyNL On BEST ANSWER

I'm still unsure on why I ran into this issue, but I've fixed my problem with a small change in my base templates.

I have a block called "head" in my base templates. Which included 2 external templates for the default css and js files (which should always be included). When I moved the contents of these templates into the base template my problem went away. The problem was only present for those css+js files. In other places the problem was not present.

It might also be related to calling the parent() template, which would be done to add aditional css or javascript on specific pages.

1
Alex Sirik On

symfony2.7 parse files differently, depending on the file extension (or name).

Variable "asset_url" is secured (and no escaped) only in .html.twig files. In other case (for examle: head.js.twig, head_js.twig etc. ), it will escaped and, accordingly, require "| raw" filter.