模板仅在 html 中显示

Template is showing only in html

我在渲染带有基本模板扩展的页面时遇到问题,它只显示在 html 中,没有 css 或 js。 这是显示的内容: img
我试图理解这个问题,但它似乎不合逻辑,因为它是相同的暗示

这是我的树枝页面:

{% extends 'base-back.html.twig'%}

{% block title %}Edit DossierEmprunteur{% endblock %}

{% block body %}
    <h1>Edit DossierEmprunteur</h1>

    {{ include('dossier_emprunteur/_form.html.twig', {'button_label': 'Update'}) }}

    <a href="{{ path('dossier_emprunteur_index') }}">back to list</a>


    {{ include('dossier_emprunteur/_delete_form.html.twig') }}
{% endblock %}

这是我的模板库:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/docs/4.1/assets/img/favicons/favicon.ico">

    <title>Dashboard Template for Bootstrap</title>

    <link rel="canonical" href="https://getbootstrap.com/docs/4.1/examples/dashboard/">

    <!-- Bootstrap core CSS -->
    <link href="../../dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="dashboard.css" rel="stylesheet">
  </head>

  <body>
  {{ include('inc/navbar.html.twig')}}



  <div class="container-fluid" style="margin-top: 50px">
      <div class="row">
        <nav class="col-md-2 d-none d-md-block bg-light sidebar">
          <div class="sidebar-sticky">
            <ul class="nav flex-column">
              <li class="nav-item">
                <a class="nav-link active" href="#">
                  <span data-feather="home"></span>
                  Dashboard <span class="sr-only">(current)</span>
                </a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">
                  <span data-feather="file"></span>
                  Orders
                </a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">
                  <span data-feather="shopping-cart"></span>
                  Products
                </a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">
                  <span data-feather="users"></span>
                  Customers
                </a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">
                  <span data-feather="bar-chart-2"></span>
                  Reports
                </a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">
                  <span data-feather="layers"></span>
                  Integrations
                </a>
              </li>
            </ul>

            <h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
              <span>Saved reports</span>
              <a class="d-flex align-items-center text-muted" href="#">
                <span data-feather="plus-circle"></span>
              </a>
            </h6>
            <ul class="nav flex-column mb-2">
              <li class="nav-item">
                <a class="nav-link" href="#">
                  <span data-feather="file-text"></span>
                  Current month
                </a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">
                  <span data-feather="file-text"></span>
                  Last quarter
                </a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">
                  <span data-feather="file-text"></span>
                  Social engagement
                </a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">
                  <span data-feather="file-text"></span>
                  Year-end sale
                </a>
              </li>
            </ul>
          </div>
        </nav>


        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-4">
          <div class="row">
            {% block body %}{% endblock %}

                  </div>




        </main>
      </div>
    </div>


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery-slim.min.js"><\/script>')</script>
    <script src="../../assets/js/vendor/popper.min.js"></script>
    <script src="../../dist/js/bootstrap.min.js"></script>

    <!-- Icons -->
    <script src="https://unpkg.com/feather-icons/dist/feather.min.js"></script>
    <script>
      feather.replace()
    </script>


  </body>
</html>

在其他页面中它呈现正确但在编辑页面中没有

因为您使用的是相对路径,所以当您的 URL 获得额外关卡时,文件将不会加载。

替换

<link href="../../dist/css/bootstrap.min.css" rel="stylesheet">
<link href="dashboard.css" rel="stylesheet">

<script src="../../assets/js/vendor/popper.min.js"></script>
<script src="../../dist/js/bootstrap.min.js"></script>

{# File location: "public/dist/css/bootstrap.min.css" #}
<link href="{{ asset('dist/css/bootstrap.min.css') }}" rel="stylesheet">
{# File location: "public/dashboard.css" #}
<link href="{{ asset('dashboard.css') }}" rel="stylesheet">

{# File location: "public/assets/js/vendor/popper.min.js" #}
<script src="{{ asset('assets/js/vendor/popper.min.js') }}"></script>
{# File location: "public/dist/js/bootstrap.min.js" #}
<script src="{{ asset('dist/js/bootstrap.min.js') }}"></script>

Symfony 4.4 文档:Linking to CSS, JavaScript and Image Assets