刀片:如何在一个页面中包含一个部分而在另一个页面中不包含

时间:2015-12-15 10:56:18

标签: laravel laravel-5 blade laravel-blade

我有一份报告,我在屏幕上出现。

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部分。 含义我有两个相同的报告,但不应打印第2部分。

你怎么能这样做?

1 个答案:

答案 0 :(得分: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
相关问题