【发布时间】:2013-09-21 08:32:40
【问题描述】:
我希望能够在一个视图中多次重复部分内容,每次重复都有不同的内容。
partial 是一个简单的面板,带有标题和一些内容。每个面板中的内容的复杂程度可能会有所不同,因此我希望能够使用@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
第一个面板按预期显示,但第二个面板只是第一个面板的重复。
我该如何纠正这个问题?如果这是完成这项工作的糟糕方法,还有什么更好的方法?
【问题讨论】: