无法使用“资产”功能添加CSS

时间:2018-07-05 14:43:48

标签: css symfony twig

我有一个小项目,我在Webpack encore中使用symfony 4.1。我正在尝试包含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 %}

我要包含的两个文件是:main.css和util.css(我不拥有这两个文件)。关于前端,我是一个菜鸟,刚刚起步。

3 个答案:

答案 0 :(得分:2)

要加载位于range P=1..3; range N=1..4; int Dem[p in 1..3]=p; int Max_Rema=3; dvar int Q4[N][P]; dvar int Q6[N][P]; subject to { forall(p in P) sum(n in N)Q6[n][p]==minl (Max_Rema*Dem[p],sum(m in N)Q4[m][p]) ; } 下的文件,请使用以下web > assets > css > style.css

答案 1 :(得分:2)

除了Andrew Vakhniuk答案

在html中,<head>标签不应位于<body>

您可能必须为此使用一个块

{# 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>

然后,您只能使用

将指定的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">

答案 2 :(得分:0)

我必须在以下位置修改xamp配置文件:C:\ xampp \ apache \ conf \ extra \ httpd-vhosts.conf

<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>