当使用Symfony2在Twig中使用{%stylesheets%}标记时,通过Twig运行CSS文件 [英] Run CSS file through Twig when using {% stylesheets %} tag in Twig with Symfony2

查看:155
本文介绍了当使用Symfony2在Twig中使用{%stylesheets%}标记时,通过Twig运行CSS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的模板中包含CSS样式表:

  {%stylesheets 
@ SomeBundle /资源/ assets / css / default.css.twig
@ SomeBundle / Resources / assets / css / global.css.twig
%}
< link rel =stylesheet href ={{asset_url}}/>但是我想通过Twig来运行这些CSS文件,因为它是通过Twig来运行这些CSS文件的。这在任何方式使用 {%stylesheets%} 标记,或者这需要一些其他的方法。我已经尝试启用 twig 过滤器,但不存在。

解决方案

如果将css作为内部样式表加载,您可以这样做。这样的东西:

  {%block stylesheets%} 
{{parent()}}
{ %include'AcmeBundle:Bundle:mycss.css.twig'%}
{%endblock%}

然后mycss.css.twig模板将包含:

 < style type =text / css> ; 
/ * * /
< / style>


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

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.

解决方案

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

And then the mycss.css.twig template would contain:

<style type="text/css">
    /* */
</style>

这篇关于当使用Symfony2在Twig中使用{%stylesheets%}标记时,通过Twig运行CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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