无法使用“包含CSS”;“资产”;功能

无法使用“包含CSS”;“资产”;功能,css,symfony,twig,Css,Symfony,Twig,我有一个小项目,我正在使用symfony 4.1和网页包encore。我试图包括一个CSS文件,但它没有加载。在Opera(开发工具)中打开网络选项卡,我可以看到加载时出现404错误。我已将“资产”放在新创建的“web”文件夹中,因为它似乎是“资产”功能识别它们的唯一地方。我没有主意了 我的小枝模板如下所示: {% block title %} Ads {% endblock %} {% block body %} <head> <link rel=

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

我的小枝模板如下所示:

{% 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 %}
{%block title%}Ads{%endblock%}
{%block body%}
身份证件
标题
描述
价格
类别
开始
终点
{ads%中的广告为%s}
{{ad.id}}
{{ad.description}}
{{ad.price}}
{{ad.category.name}
{{ad.startDate}日期('d:m:Y')}
{{ad.expiryDate}日期('d:m:Y')}
删除
{%endfor%}
{%endblock%}

我想包含的两个文件是:main.css和util.css(我不拥有这两个文件)。说到前端,我是个新手,刚刚开始

要加载位于
web>assets>css>style.css下的文件,您应该使用以下

来加载位于
web>assets>css>style.css下的文件。除了Andrew Vakhniuk答案之外,您还应该使用以下

在html中,
标记不应位于

你可能需要用一个积木

{# templates/base.html.twig #}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>{% block title %}Test Application{% endblock %}</title>

        {# CSS included in all pages #}
        <link rel="stylesheet" type="text/css" href="{{ asset('assets/css/main.css') }}">
        {# CSS included in special pages #}
        {% block stylesheets %}{%enblock%}
    </head>
{#templates/base.html.twig}
{%block title%}测试应用程序{%endblock%}
{#CSS包含在所有页面中#}
{#特殊页面中包含CSS#}
{%block样式表%}{%enblock%}
然后,您可以使用以下命令仅将指定的css添加到此单个页面

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

{% block stylesheets %}
     {# it will replace the content of the block of base.html.twig". use {{ parent() }} to add cotnent isntead of replace it %}
     <link rel="stylesheet" type="text/css" href="{{ asset('assets/css/util.css') }}">
{% endblock %}

{% block body %}
    <div class="limiter">
                <div class="container-table100">
                    <div class="wrap-table100">
{%block title%}Ads{%endblock%}
{%块样式表%}
{#它将替换base.html.twig.块的内容。使用{{parent()}}添加替换它%}的组件isntead
{%endblock%}
{%block body%}

除了Andrew Vakhniuk的回答

在html中,
标记不应位于

你可能需要用一个积木

{# templates/base.html.twig #}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>{% block title %}Test Application{% endblock %}</title>

        {# CSS included in all pages #}
        <link rel="stylesheet" type="text/css" href="{{ asset('assets/css/main.css') }}">
        {# CSS included in special pages #}
        {% block stylesheets %}{%enblock%}
    </head>
{#templates/base.html.twig}
{%block title%}测试应用程序{%endblock%}
{#CSS包含在所有页面中#}
{#特殊页面中包含CSS#}
{%block样式表%}{%enblock%}
然后,您可以使用以下命令仅将指定的css添加到此单个页面

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

{% block stylesheets %}
     {# it will replace the content of the block of base.html.twig". use {{ parent() }} to add cotnent isntead of replace it %}
     <link rel="stylesheet" type="text/css" href="{{ asset('assets/css/util.css') }}">
{% endblock %}

{% block body %}
    <div class="limiter">
                <div class="container-table100">
                    <div class="wrap-table100">
{%block title%}Ads{%endblock%}
{%块样式表%}
{#它将替换base.html.twig.块的内容。使用{{parent()}}添加替换它%}的组件isntead
{%endblock%}
{%block body%}

我不得不修改C:\xampp\apache\conf\extra\httpd-vhosts.conf中的xamp配置文件

<VirtualHost *:80>
    ServerName adsmanagement.test
    ServerAlias adsmanagement.test

    DocumentRoot C:/xampp/htdocs/ads-management/public
    <Directory C:/xampp/htdocs/ads-management/public>
        AllowOverride All
        Order Allow,Deny
        Allow from All

        FallbackResource /index.php
    </Directory>

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeeScript assets
    # <Directory /var/www/project>
    #     Options FollowSymlinks
    # </Directory>

    ErrorLog logs/ads_management.log
    CustomLog logs/ads_management_custom.log combined
</VirtualHost>

ServerName adsmanagement.test
ServerAlias adsmanagement.test
DocumentRoot C:/xampp/htdocs/ads management/public
允许超越所有
命令允许,拒绝
通融
FallbackResource/index.php
#如果将资产安装为符号链接,请取消注释以下行
#或者在编译更少的/Sass/CoffeeScript资产时遇到问题
# 
#选项如下符号链接
# 
错误日志/ads_management.log
CustomLog日志/ads\u管理\u custom.log组合

我不得不修改C:\xampp\apache\conf\extra\httpd-vhosts.conf中的xamp配置文件

<VirtualHost *:80>
    ServerName adsmanagement.test
    ServerAlias adsmanagement.test

    DocumentRoot C:/xampp/htdocs/ads-management/public
    <Directory C:/xampp/htdocs/ads-management/public>
        AllowOverride All
        Order Allow,Deny
        Allow from All

        FallbackResource /index.php
    </Directory>

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeeScript assets
    # <Directory /var/www/project>
    #     Options FollowSymlinks
    # </Directory>

    ErrorLog logs/ads_management.log
    CustomLog logs/ads_management_custom.log combined
</VirtualHost>

ServerName adsmanagement.test
ServerAlias adsmanagement.test
DocumentRoot C:/xampp/htdocs/ads management/public
允许超越所有
命令允许,拒绝
通融
FallbackResource/index.php
#如果将资产安装为符号链接,请取消注释以下行
#或者在编译更少的/Sass/CoffeeScript资产时遇到问题
# 
#选项如下符号链接
# 
错误日志/ads_management.log
CustomLog日志/ads\u管理\u custom.log组合

我试过了,因为一些奇怪的原因,它不起作用。如果我这样做,PHPStorm会通知我找不到该资产。我尝试了,但由于某些奇怪的原因,它不起作用。如果我这样做,PHPStorm将通知我无法找到资产。无法工作。我尝试使用样式表块以及带有href的绝对路径来使用您的方法。仍然得到一个404错误。PS.修复了头部问题,哑巴不起作用。我尝试使用样式表块以及带有href的绝对路径来使用您的方法。仍然得到一个404错误。附言:修正了头部问题,哑巴。