Run CSS file through Twig when using {% stylesheets %} tag in Twig with Symfony2(在带有 Symfony2 的 Twig 中使用 {% stylesheets %} 标签时通过 Twig 运行 CSS 文件)
问题描述
我在我的模板中包含 CSS 样式表,如下所示:
I'm including CSS stylesheets in my template like so:
{% stylesheets
"@SomeBundle/Resources/assets/css/default.css.twig"
"@SomeBundle/Resources/assets/css/global.css.twig"
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
但是我想通过 Twig 运行这些 CSS 文件,这在使用 {% stylesheets %}
标记时是否有可能,或者这是否需要一些其他方法.我已经尝试启用 twig
过滤器,但它不存在.
However I want to run these CSS files through Twig, is this in any way possible while using the {% stylesheets %}
tag or does this require some other approach. I've already tried enabling a twig
filter but that does not exist.
推荐答案
如果您将 css 作为内部样式表加载,您可以做到这一点.像这样的:
You could do it if you load the css as an internal stylesheet. Something like this:
{% block stylesheets %}
{{ parent() }}
{% include 'AcmeBundle:Bundle:mycss.css.twig' %}
{% endblock %}
然后 mycss.css.twig 模板将包含:
And then the mycss.css.twig template would contain:
<style type="text/css">
/* */
</style>
这篇关于在带有 Symfony2 的 Twig 中使用 {% stylesheets %} 标签时通过 Twig 运行 CSS 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在带有 Symfony2 的 Twig 中使用 {% stylesheets %} 标签时通过 Twig 运行 CSS 文件


基础教程推荐
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01