我有以下文件:
foo.blade.php
<html>
<head>
</head>
<body>
<h1>Foo Template</h1>
@yield('content')
</body>
</html>
bar.blade.php
<h2>Bar Template</h2>
<div class="bar-content">
@yield('bar-content')
</div>
我想创建另一个能够扩展上述两个模板的文件。例如这样的事情:
@extends('foo')
@section('content')
<p>Hello World</p>
@extends('bar')
@section('bar-content')
<p>This is in div.bar-content</p>
@endsection
@endsection
给予:
<html>
<head>
</head>
<body>
<h1>Foo Template</h1>
<p>Hello World</p>
<h2>Bar Template</h2>
<div class="bar-content">
<p>This is in div.bar-content</p>
</div>
</body>
</html>
我怎样才能做到这一点?
最佳答案
使用多个文件。
例如
layout.blade.php:
@include('header')
@yield('layout_content')
@include('footer')
second.blade.php
@extends('layout')
@section('layout_content')
<div>
@yield('second_content')
</div>
@stop
third.blade.php
@extends('second.blade.php')
@section('second_content')
<h1>Hello World!</h1>
@stop
您可以在任何父文件中包含@yield,并且可以在子文件中使用
关于laravel - 如何在Blade(Laravel 5)中扩展多个模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35798721/