2016-01-04 58 views
0

有没有包含Laravel刀片视图的部分的方法仅包含Laravel刀片视图的部分


我有一个基本视图,通常包含在这个视图内的内容。有时我需要更多的自由度,想要更简单的基础,所以我将$special标志设置为true。现在我有一种观点,可能都是作为一种“特殊”和正常观点出现的。有没有干净的方法来干这个?

base.blade.php

<!DOCTYPE html> 
<html> 
<head> 
    <title>@yield("title", "placeholder") - website</title> 
</head> 
<body> 
    @if (isset($special) && $special) 
     @yield("content") 
    @else 
     <header> 
      website 
     </header> 
     <main> 
      @yield("content") 
     </main> 
     <footer>&copy; 2099</footer> 
    @endif 
</body> 
</html> 

article.blade.php

@extends("base") 

@section("title", "10 ways! You won't follow the last!") 

@section("content") 
So much content. 
@endsection 

other.blade.php

@extends("base", ["special" => true]) 

@section("title", "Welcome") 

@section("content") 
<div id="start"> 
    Other stuff 
</div> 
<div id="wooo"> 
    <main> 
     @include("article") ← does not work 
    </main> 
    <footer>&copy; 2099</footer> 
</div> 
@endsection 

回答

0

我最终作出新的刀片文件仅包含部分。然后这两个页面都包含该刀片模板。

article.blade.php

@extends("base") 

@section("title", "10 ways! You won't follow the last!") 

@section("content") 
@include("common") 
@endsection 

other.blade.php

@extends("base", ["special" => true]) 

@section("title", "Welcome") 

@section("content") 
<div id="start"> 
    Other stuff 
</div> 
<div id="wooo"> 
    <main> 
     @include("common") 
    </main> 
    <footer>&copy; 2099</footer> 
</div> 
@endsection 

common.blade.php

So much content. 
0

我通常做像这样:

我创建了一个base.blade.php,其中包含布局的核心内容。

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Document</title> 
</head> 
<body> 

    @yield('body-content') 

</body> 
</html> 

然后我创建其他模板,扩展基本文件。

例如:
template.blade.php

@extends('base') 

@section('body-content') 

    <header> 
     website 
    </header> 
    <main> 
     @yield("content") 
    </main> 
    <footer>&copy; 2099</footer> 

@endsection 

someOtherTemplate.blade.php

@extends('base') 

@section('body-content') 
    <main> 
     @yield("content") 
    </main> 
@endsection 

现在只是延长,你需要哪个模板。

相关问题