【发布时间】:2014-02-05 19:26:59
【问题描述】:
我有主布局模板/views/web/main_lo.blade.php
<html>
<head>
<meta charset="UTF-8">
<title>{{$title or 'Default Title'}}</title>
</head>
<body>
<div class="section-1-outer">
@section('section-1')
<div class="section-1-parent">parent section 1</div>
@show
</div>
<div class="section-2-outer">
@section('section-2')
<div class="section-2-parent">parent section 2</div>
@show
</div>
<div class="section-3-outer">
@section('section-3')
<div class="section-3-parent">parent section 3</div>
@show
</div>
<div>
@yield('content')
</div>
</body>
</html>
和一个部分模板:
@extends('web.main_lo')
@section('section-1')
@parent
<div class='section-1-child'>
<p>Appended to parent</p>
</div>
@stop
@section('section-2')
<div class='section-2-child'>
<p>Replace parent</p>
</div>
@stop
@section('section-3')
<div class='section-3-child'>
<p>Replace parent</p>
</div>
@overwrite
现在这里的部分布局扩展了main_lo,这里的First section-1很清楚,子部分将包括父部分1,并且父部分中的内容也会被打印出来。
现在我的困惑是第 2 节和第 3 节实现之间到底有什么区别,因为它们都替换了父节的内容,并且只有子节中的内容被打印出来。我的意思是当documentation 明确指出时,需要这个额外的@overwrite 标签
"请注意,扩展 Blade 布局的视图只是覆盖部分 从布局。”
然后有 Overwriting Sections 使用@overwrite 也用于替换父节的内容。
【问题讨论】:
-
好问题。这里有一些指导:laravel-recipes.com/recipes/244