css - 无法使用 "asset"函数包含 CSS

标签 css symfony twig

我有一个小元素,我正在使用带有 Webpack encore 的 symfony 4.1。我试图包含一个 CSS 文件,但它没有加载。在 Opera(开发工具)中打开网络选项卡,我可以在加载时看到 404 错误。我将“ Assets ”放在新创建的“web”文件夹中,因为它似乎是“ Assets ”功能识别它们的唯一地方。我没主意了。

我的 Twig 模板如下所示:

{% block title %} Ads {% endblock %}

{% block body %}

    <head>
        <link rel="stylesheet" type="text/css" href="{{ asset('css/main.css') }}">
        <link rel="stylesheet" type="text/css" href="{{ asset('css/util.css') }}">
    </head>

    <div class="limiter">
                <div class="container-table100">
                    <div class="wrap-table100">
                        <div class="table100">
                            <table class="table">
                                <thead class="thead-dark">
                                    <tr>
                                        <th scope="col">ID</th>
                                        <th scope="col">Title</th>
                                        <th scope="col">Description</th>
                                        <th scope="col">Price</th>
                                        <th scope="col">Category</th>
                                        <th scope="col">Start</th>
                                        <th scope="col">End</th>
                                        <th scope="col"></th>
                                        <th scope="col"></th>
                                    </tr>
                                </thead>

                                <tbody>
                                    {% for ad in ads %}
                                        <tr>
                                            <th scope="row">{{ ad.id }}</th>
                                            <td> <a href="{{ path('ad',{'id':ad.id}) }}">{{ ad.title }}</a></td>
                                            <td>{{ ad.description }}</td>
                                            <td>{{ ad.price }}</td>
                                            <td>{{ ad.category.name}}</td>
                                            <td>{{ ad.startDate|date('d:m:Y') }}</td>
                                            <td>{{ ad.expiryDate|date('d:m:Y') }}</td>
                                            <td><a class="btn btn-primary btn" href="{{ path('edit_ad',{'id':ad.id}) }}" role="button"> Edit</a></td>
                                            <td> <form action="{{ path('delete_ad',{'id':ad.id}) }}" method="post"> <button type="submit" class="btn btn-default">Delete</button> </form> </td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
{% endblock %}

我想包含的两个文件是:main.css 和 util.css(我不拥有这两个文件)。说到前端,我是个菜鸟,刚入门。

最佳答案

加载位于web > assets > css > style.css下的文件您应该使用以下 <link rel="stylesheet" type="text/css" href="{{ asset('assets/css/style.css') }}">

关于css - 无法使用 "asset"函数包含 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51194188/

相关文章:

php - 如何使用 json_encode twig 函数在 twig 文件中使用 php json_encode 选项

css - 保持两个div的长度相同

html - 如何设置 DIV 样式以显示 html 控件

javascript - 我想用javascript在控制台中显示匹配的记录

php - 尝试在 slim 中使用 twig 时出错, fatal error :TwigView::getEnvironment()

symfony - 在 Twig 模板中过滤 bool 变量

php - 如何在 TWIG 中使用转储?

css - 如何应用溢出:隐藏到内容框?

php - 单个 symfony 路由中的多个模式

javascript - 使用 jquery 使用 twig 值填充输入字段