Blade: 如何在一个页面中包含一个部分,但不在另一个页面中

Blade: how to include a section in one page but not in another

我在屏幕上显示了一份报告。

report.blade.php

<html>
    <head>
    </head>
    <body>
        @yield('content')
    </body>
</html>

report_sub1.blade.php

@extends('reports.report')

@section('content')
    <h1> This is sub section 1 </h1>

    <h1> This is sub section 2 </h1>
@stop

我想在第一份报告中包含第 2 部分,但不包含在第二份报告中。 这意味着我有两份相同的报告,但其中一份不应打印第 2 部分。

你怎么做到的?

您可以将 report.blade.php 用作母版页。然后使用两个部分作为子部分,并使用第三个部分作为 section 1。最后仅在您需要的地方包括最后一部分:

section1.php

<!-- section 1 definition-->
<h1> This is sub section 1 </h1>   

report_sub1.blade.php

@extends('reports.report')

@section('content')
     <!-- section 1 included -->
     @include('section1')

     <!-- section 2 included only here--> 
     <h1> This is sub section 2 </h1>  
@stop

report_sub2.blade.php

@extends('reports.report')

@section('content')
     <!-- section 1 included -->
    @include('section1') 

    <!-- section 2 included is not included here-->   
@stop