2017-06-30 40 views
0

我有一個文件夾中查看:在Laravel使用刀片時如何安排內容的顯示位置?

resources -> view 
       - layouts 
        + master.blade.php 
       - partials 
        + footer.blade.php 
        + header.blade.php 
       - news 
        + show.blade.php 
        + list.blade.php 
       - apartment 
        + show.blade.php 

我的代碼在master.blade.php

<head> 
    <script src="{{{ URL::asset('js/theme.min.js')}}}"></script> 
</head> 
<body> 
    <div class="main-container"> 
     @include('partials.header') 
     @yield('content') 
     @include('partials.footer') 
    </div> 
</body> 

news>show.blade.php

@extends('layouts.master') 
@section('content') 
    <div class="show-news">show all news at here</div> 
@stop 

apartment>show.blade.php

@extends('layouts.master') 
@section('content') 
    <div class="show-apartment">show all apartment at here</div> 
@stop 

在HTML文件中有結構一樣:

header 

content 
    - show slider image 
    - show list news 
    - show list apartment 
footer 

因爲所有文件與section('content')定義。

我不知道如何使用我的HTML文件正確排列section('content')的顯示位置。

我想應該是這樣的:

news>show.blade.php:@section( '新聞')

apartment>show.blade.php:@section( '公寓')

master.blade.php

<head> 
    <script src="{{{ URL::asset('js/theme.min.js')}}}"></script> 
</head> 
<body> 
    <div class="main-container"> 
     @include('partials.header') 
     @yield('news') 
     @yield('apartment') 
     @include('partials.footer') 
    </div> 
</body> 

但是我幾乎看到項目上都不這樣用。

回答

0

您可以創建一個繼承母版頁這樣

master.blade.php另一個頁面佈局

<head> 
    <script src="{{{ URL::asset('js/theme.min.js')}}}"></script> 
</head> 
<body> 
    <div class="main-container"> 
     @include('partials.header') 
     @yield('content') 
     @include('partials.footer') 
    </div> 
</body> 

newlayout.blade.php

@extends('master') 
@section('content') 
    @yield('news') 
    @yield('appartments') 
@endsection 

你也可以使用此佈局對於像你所描述的頁面,對於另一個你可以使用主人

相關問題