跨继承的模板组合资产资源 [英] Combining Assetic Resources across inherited templates

查看:21
本文介绍了跨继承的模板组合资产资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 Symfony2 构建一个新站点,Assetic 在资源管理方面看起来非常有前途,特别是在自动组合和处理所有 js/css 文件方面.

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 automatically.

我们将拥有一些在网站范围内使用的资源,以及一些特定于特定页面的资源.我们还将对模板使用三层继承方法.

We wil have some resources that are used site wide, and some that are specific to particular pages. We will also be using a three tiered inherited approach to templates.

有没有办法将这两个概念结合起来,即在继承的模板中自动添加额外的资源,以便它们都作为单个资源输出?

Is there a way to combine the two concepts, i.e. to automatically add additional resources in inherited templates so that they are all output as a single resource?

推荐答案

很遗憾,你不能:(

您不能覆盖资产标签来添加更多资产.但是,您可以执行以下操作:

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 %}

在被覆盖的块中,你可以使用 parent() 来包含父块,但是你会有两个链接:你不能将旧的资产标签与新的标签结合起来.

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.

但是,您可以创建一个 twig 宏,将 {% stylesheets %} 资产标签与您的旧资产一起输出,并作为输入包含新资产位置.

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.

更多信息这里.

这篇关于跨继承的模板组合资产资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆