dsc56927 2013-10-06 09:29
浏览 23
已采纳

Symfony 2资产路径

i didnt understand how assethic paths works..

{% block stylesheets %}
            <link href="{{ asset('/bundles/dproc/css/base.css') }}" type="text/css" rel="stylesheet" />
        {% endblock %}

My css and images are in /bundles/dproc/ directory. The code i showed below works, but i cant understand why should i use asset function, i can do it like this and get the same result

{% block stylesheets %}
            <link href="/bundles/dproc/css/base.css" type="text/css" rel="stylesheet" />
        {% endblock %}

So what does asset function? Or how should my path look like with asset function?

  • 写回答

1条回答 默认 最新

  • doqp87012 2013-10-06 09:35
    关注

    Because you probably shouldn't even use it like that. You should probably use Assetic with css like this:

    {% block stylesheets %}
        {% stylesheets
        '/bundles/dproc/css/base.css' {# this will just get base.css #}
        '/bundles/dproc/css/mycustomdir/* {# this will find all css files in that dir #}
        %}
        <link href="{{ asset_url }}" rel="stylesheet">
        {% endstylesheets %}
    {% endblock %}
    

    By setting it up like this (with default config), in dev environment you will get exactly the same thing as if you just used <link .... > without assetic. But in production environment, your whole stylesheets assetic block will be merged into one file to reduce number of requests.

    Later, you can set up some css and javascript minifiers and make them run in production environment. So, when you switch to production, you will have nice,economic css and javascript, while in dev invironment you will have exactly what you'd expect if you didn't use assetic at all.

    Furthermore, if you use less or sass or something that needs to be precompiled, you could just include those files and tell assetic to recompile them automatically when they are changed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 被蓝屏搞吐了,有偿求帮解答,Ai回复直接拉黑
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角