2016-10-13 85 views
3

我有兩個幾乎相同的模板。這是郵件模板,但它應該在兩個不同的地方。所以他們擴展了兩個不同的模板,但是這個和部分名稱是唯一的區別。Laravel刀片模板擴展了兩種不同的佈局

這裏的例子:

@extends('layout.client') 
    //sections etc 
@section('content') 
    //content here 
@endsection 
    //other sections etc 

這裏是第二個模板:

@extends('layout.company') 
    //sections etc 
@section('contentinner') 
    //content here 
@endsection 
    //other sections etc 

的其他部分大多是進口圖書館,使工作內容。

我該如何解決這個問題,以避免重複代碼?

回答

3

創建另一個模板,並在您的部分

<div class="col-md-3"> 
    @include('layouts.your_template') 
</div> 
0

我使用components解決類似的問題。

我發現擁有一個主佈局是很好的,但是如果您需要在許多頁面中包含部分代碼,最好使用組件。 This提供了組件使用的一個很好的例子。

把你的模板到components.yourtemplate.blade.php

然後在這兩個layout.clientlayout.company

@component('components.yourtemplate') 
@endcomponent 
要包含你的模板代碼

。您可以在許多視圖中包含相同的組件。