Asset cache crashes with parameterized URL with Assetic

How to configure asset versioning through Assetic in Symfony 3.2?

In Symfony 2, this could be achieved by setting the version of packages in framework:templating, but this is no longer the case in 3.

I tried using the following configuration:

framework:
  assets:
    packages:
      css:
        version: '2'
        version_format: '%%s?version=%%s'

When using this in a template:

{% stylesheets output="css/global.css" "@AppBundle/Resources/assets/scss/frontend.scss" filter="scss" filter="?uglifycss" package="css" %}
    <link rel="stylesheet" href="{{ asset(asset_url) }}">
{% endstylesheets %}

Unfortunately, this does not add the version parameter to the resource URL, despite the fact that Symfony's official asset documentation offers .

+4
source share
2 answers

I managed to solve this after some further research: you must specify the package name when calling the asset () function, for example:

{% stylesheets output="css/global.css" "@AppBundle/Resources/assets/scss/frontend.scss" filter="scss" filter="?uglifycss" %}
     <link rel="stylesheet" href="{{ asset(asset_url, 'css') }}">
{% endstylesheets %}

"css" config:

framework:
  assets:
  packages:
    css:
      version: '2'
      version_format: '%%s?version=%%s'
0

"", :

parameters:
    app_version: 1.0.0

framework:
    assets:
        version:   '%app_version%'
        version_format: '%%1$s?%%2$s'
        base_urls: ['%your_assets_urls%']
0

Source: https://habr.com/ru/post/1674771/


All Articles