0

我在这里找到了如何在 Twig 模板上引用资产文件:如何在 Symfony 2 和 Twig 中包含 CSS 文件?

它说我应该像这个例子一样在路径中包含 bundle 文件夹:{{ asset('bundles/mybundle/css/main.css') }}

这个解决方案对我来说不可靠,因为我有许多网站模板,其中包含大量资产文件引用(JS、CSS、图像),我需要将其转换为 Twig 模板,而且我很难用我提到的完整路径替换所有资产路径在示例中。如果我可以这样使用它至少会更容易:{{ asset('css/main.css') }}

谁能帮我解决这个问题?谢谢大家。

4

2 回答 2

2

The news best practices recommended by Symfony are now to regroup the assets of your app in the web/ folder, you loose a bit of the re usability of your code but you get rid of a lot of suffering in your asset management.

This way you will be "able" (without thinking you are doing some dirty developement ;) ) to store your CSS in the web/css/ folder you made and then call them with

{{ asset('css/main.css') }}

http://symfony.com/doc/current/best_practices/web-assets.html

"Best Practice :

Store your assets in the web/ directory."

于 2014-12-09T09:57:55.523 回答
1

您可以将所有 css 包含在这样的文件夹中:

{% stylesheets 'bundles/main/js/lightbox/css/*' filter='cssrewrite' %}
    <link href="{{ asset_url }}" rel="stylesheet" type="text/css" />
{% endstylesheets %}
于 2013-06-21T18:37:31.070 回答