Assetic、图像资源和缓存
我正在努力将 Assetic 集成到我正在构建的应用程序中。该应用程序遵循 MVC 模式,但不使用任何框架。 Twig 用于模板化。
该应用程序的结构如下:
- 应用程序
- twig_templates
- js
- CSS
- public_html
- js
- CSS
- 图片
树枝模板被渲染,然后由应用程序返回,所以这非常简单。 application
文件夹下的 js
和 css
文件夹将保存原始 javascript 和 css 文件。
我的计划是,合并和缩小的 js 和 css 文件将存储在 public_html 文件夹下的 js 和 css 文件夹中。
由于我不打算使用 assetic 优化任何图像,因此它们将直接放置在 public_html
下的 images
文件夹中。
现在的问题是:
我知道通过使用 twig 中的 assetic,组合和缩小的资源可以导出到我的 public_html 目录:
{% stylesheets '/path/to/sass/main.sass' filter='sass,?yui_css' output='css/all.css' %} > {% endstylesheets %}
在这种情况下,每次渲染模板时都会重新生成
css/all.css
文件吗?使应用程序可移植(可以使用虚拟主机托管,甚至可以在文件夹中托管)并确保在具有路由 URL(例如
http://site.com/controller/)的站点中正常工作操作
,assetic是否提供将图像的URL“重写”为绝对URL(即images/a.jpg
到http://mysite.com/images/a.jpg
)?使用嵌套模板时 assetic 是否有效?
parent.twig:
; <头> {% 区块头 %}
{% block title %}{% endblock %} - 我的网页 {% 末端嵌段 %} <正文>child.twig:
{% 扩展“parent.twig” %} {% 块标题 %}索引{% endblock %} {% 区块头 %} {{ 父级() }} {% 末端嵌段 %}
在这种情况下,我如何让 assetic 知道它应该结合
childstyle.css
和mainstyle.css
并将其作为 1 个文件提供?
I am working on integrating Assetic into an application that I am building. The application follows the MVC pattern but does not use any frameworks. Twig is used for templating.
I have read the documentation and have looked at a few helpful blog posts.
The application is structured like this:
- application
- twig_templates
- js
- css
- public_html
- js
- css
- images
The twig templates are rendered and then returned by the application, so that is quite straight forward. The js
and css
folders underneath the application
folder would hold the raw javascript and css files.
My plan is that combined and minified js and css files would be stored in the js
and css
folders under the public_html folder.
Since I don't plan to optimize any images using assetic, they will be placed in the images
folder underneath public_html
directly.
Now the question:
I understand that by using assetic from twig, combined and minified assets can be exported to my public_html directories:
{% stylesheets '/path/to/sass/main.sass' filter='sass,?yui_css' output='css/all.css' %} <link href="{{ asset_url }}" type="text/css" rel="stylesheet" /> {% endstylesheets %}
In this case is the
css/all.css
file regenerated everytime that template is rendered?To make the application portable (it could be hosted using a virtual host, or perhaps even in a folder) and to ensure things work in a site with routed URLs like
http://site.com/controller/action
, does assetic provide anyway "rewrite" URLs for images into absolute ones (i.e.images/a.jpg
intohttp://mysite.com/images/a.jpg
)?Does assetic work when using nested templates?
parent.twig:
<!DOCTYPE html> <html> <head> {% block head %} <link rel="stylesheet" href="mainstyle.css" /> <title>{% block title %}{% endblock %} - My Webpage</title> {% endblock %} </head> <body> </body> </html>
child.twig:
{% extends "parent.twig" %} {% block title %}Index{% endblock %} {% block head %} {{ parent() }} <link rel="stylesheet" href="childstyle.css" /> {% endblock %}
In this case, how can I let assetic know that it should combine
childstyle.css
andmainstyle.css
and serve it as 1 file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
至于这个答案,不可能将从父级继承的样式表与子级的样式表结合起来
跨继承模板组合 Assetic 资源
as for this answer it is not possible to combine inherited stylesheets from parent with child's
Combining Assetic Resources across inherited templates