我有一个小元素,我正在使用带有 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/