dsc56927 2013-10-06 01: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 01: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部