跨继承模板组合资产资源
我们正在使用 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您实际上可以执行以下操作:
在layout.html.twig(或任何您的布局)中
以及在扩展该布局的任何模板中:
然后您不需要按照Nemanja Niljkovic的建议重新输入所有旧资源
You can actually do the following:
In layout.html.twig (or whatever your layout is)
And in any template that extends that layout:
Then you wouldn't need to retype all the old assets as suggested by Nemanja Niljkovic
不幸的是,您不能:(
您无法覆盖 assetic 标签来添加更多资产。但是您可以执行以下操作:
然后,当您扩展模板时:
在覆盖的块中,您可以使用
parent()
来包含父块,但是这样您将有 2 个链接:您无法将旧的 assetic 标记与新的 assetic 标记组合起来,但是您可以创建一个 twig 宏来输出 {% stylesheets %} assetic 标记。使用您的旧资产,并且作为输入,它将包含新的资产位置。
更多信息请参见此处。
Unfortunately, you can't :(
You can't override the assetic tags to add more assets. You can however do the following:
Then, when you extend the template:
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.