【问题标题】:Blade syntax @extends loads second HTML view and then the first HTML viewBlade 语法 @extends 加载第二个 HTML 视图,然后加载第一个 HTML 视图
【发布时间】:2017-03-24 22:09:22
【问题描述】:

我是 laravel 和刀片模板引擎的新手。 问题:文件 form.blade.php

@extends('front.header') @extends('front.footer')

先加载front/footer.blade.php,再加载front/header.blade.php的内容

请在附件中找到查看源代码的快照。

我在stackoverflow中检查了他们所说的关于空白的几个答案。我似乎没有。

问候, Jignesh

【问题讨论】:

  • 您不能从 2 个父母继承。如果你想包含另一个视图,你应该使用@include('front.header')@include('front.footer')
  • 我发布了一个答案以供将来参考

标签: php blade laravel-5.3 laravel-blade


【解决方案1】:

您不能来自 2 个父母的@extends。如果你想包含另一个视图,你应该改用@include

像这样:

@include('front.header')
Content
@include('front.footer')

【讨论】:

    【解决方案2】:

    这就是我建议您构建主模板的方式。

    front._layouts.master:

    <!DOCTYPE html>
    <html>
    <head>
      @include('front._layouts.head')
    </head>
    <body>
      <header>
          @include('front._layouts.header')
      </header>
    
      <main>
          @yield('content')
      </main>
    
      <footer>
        @include('front._layouts.header')
      </footer>
      @stack('scripts')
    </body>
    </html>
    

    请注意@stack(),当您制作应用程序的强大部分时,它会派上用场。 Stacks 允许您将命名堆栈推到彼此之上。

    【讨论】:

      【解决方案3】:

      按照以下步骤操作:

      第 1 步:

      resources\views 创建一个文件,如:master.blade.php

      第 2 步:

      resources\views 创建一个文件夹,例如:layouts

      layout 文件夹中创建您的headerfooter 文件

      第 3 步:

      master.blade.php 里面写下你是如何设计你的主模板的。

      <!DOCTYPE html>
      <html lang="en">
          <head>
              <!-- your common css here -->
      
              @yield('partial-css')
      
          </head>
      
          <body>
              @include('layouts.top-header')             
      
              <div class="container">
                  @yield('content') <!-- this is your common body -->
              </div> <!-- /container --> 
      
              @include('layouts.footer')
      
              <!-- your common js here or you also define inside the footer page -->
      
              @yield('script') <!-- this is your individual script for all page -->
      
          </body>
      </html>
      

      第 4 步: 现在您将母版页用于所有其他页面,例如index.blade.php

      @extends('master')
      
      @section('content')
      
      <!-- Here is your main body content -->
      
      @endsection
      
      @section('script')
      
      <!-- Here is your individual script content -->
      
      @endsection
      

      希望您现在了解刀片模板的工作原理!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多