我希望能够在一个视图中重复部分多次,每次重复都有不同的内容。
部分是一个简单的面板,带有标题和一些内容。每个面板中的内容可能复杂程度不同,所以我希望能够使用@section('content')
传递数据的方法。
我的设置如下:
panel.blade.php - 要重复的部分。
<div class="panel">
<header>
@yield('heading')
</header>
<div class="inner">
@yield('inner')
</div>
</div>
view.blade.php - 部分重复的视图
@extends('default')
@section('content')
{{-- First Panel --}}
@section('heading')
Welcome, {{ $user->name }}
@stop
@section('inner')
<p>Welcome to the site.</p>
@stop
@include('panel')
{{-- Second Panel --}}
@section('heading')
Your Friends
@stop
@section('inner')
<ul>
@foreach($user->friends as $friend)
<li>{{ $friend->name }}</li>
@endforeach
</ul>
@stop
@include('panel')
@stop
我遇到了与此相同的问题:http ://forums.laravel.io/viewtopic.php?id=3497
第一个面板按预期显示,但第二个面板只是第一个面板的重复。
我该如何纠正?如果这是完成这项工作的糟糕方法,那么更好的方法是什么?