Skip to content

Document the new Asset component + framework changes #4982

Closed
@javiereguiluz

Description

@javiereguiluz

The new Asset component has been merged in symfony/symfony#13234.

Todos:

1. Changes in configuration

# OLD configuration
framework:
    templating:
        assets_version: 'v5'
        assets_version_format: '%%s?version=%%s'
        assets_base_urls:
            http: ['http://cdn.example.com']
            ssl:  ['https://secure.example.com']
        packages:
            # ...

# NEW configuration
framework:
    assets:
        version: 'v5'
        version_format: '%%s?version=%%s'
        base_path: ~
        base_urls: ['http://cdn.example.com', 'https://secure.example.com']
        packages:
            # ...

2. Changes in Twig templates

{{ asset() }} function is the same as before, but now it only allows to set two arguments:

{# Common case: no package name #}
{{ asset('logo.png') }}

{# When using packages #}
{{ asset('logo.png', 'images') }}

This means that absolute and version arguments are no longer available:

{# BEFORE #}
{{ asset('logo.png', absolute = true) }}

{# AFTER #}
{{ absolute_url(asset('logo.png')) }}


{# BEFORE #}
{{ asset('logo.png', version = 'v5') }}

{# AFTER #}
{# relative URLs - do nothing (version is automatically appended) #}
{{ asset('logo.png') }}

{# absolute URLs - get the version with asset_version() and append it manually #}
{{ absolute_url(asset('logo.png')) ~ '?' ~ asset_version('logo.png') }}

3. Other changes

  • The asset*() functions are now defined in the Twig Bridge instead of the Twig Bundle.

4. Lastly, I have a question when using Asset component in a Symfony application: How can I use a custom version strategy in a Symfony application?

Metadata

Metadata

Assignees

No one assigned

    Labels

    AssetactionableClear and specific issues ready for anyone to take them.hasPRA Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions