Combining Assetic Resources across inherited templates

后端 未结 2 665
北恋
北恋 2020-12-02 20:52

We are building a new site using Symfony2, and Assetic looks very promising for resource management, in particular for combining and processing all js/css files together aut

相关标签:
2条回答
  • 2020-12-02 21:16

    Unfortunately, you can't :(

    You can't override the assetic tags to add more assets. You can however do the following:

    {% block stylesheets %}
        {% stylesheets 'your_assets_here' %}
             <link rel="stylesheet" href="{{ asset_url }}" />
        {% endstylesheets %}
    {% endblock %}
    

    Then, when you extend the template:

    {% block stylesheets %}
        {% stylesheets 'your_old_assets_here' 'your_new_assets_here' %}
             <link rel="stylesheet" href="{{ asset_url }}" />
        {% endstylesheets %}
    {% endblock %}
    

    In the overridden block, you can use parent() to include the parent block, but you would have 2 links then: you can't combine the old assetic tag with the new one.

    You could however make a twig macro that would output the {% stylesheets %} assetic tag with your old assets, and as input it would contain new asset locations.

    More info here.

    0 讨论(0)
  • 2020-12-02 21:21

    You can actually do the following:

    In layout.html.twig (or whatever your layout is)

    {% block stylesheets %}
        {% stylesheets 'your_assets_here' %}
             <link rel="stylesheet" href="{{ asset_url }}" />
        {% endstylesheets %}
    {% endblock %}
    

    And in any template that extends that layout:

    {% block stylesheets %}
        {{ parent() }}
        {% stylesheets 'additional_assets_here' %}
             <link rel="stylesheet" href="{{ asset_url }}" />
        {% endstylesheets %}
    {% endblock %}
    

    Then you wouldn't need to retype all the old assets as suggested by Nemanja Niljkovic

    0 讨论(0)
提交回复
热议问题