If you look to laravel official documentation http://laravel.com/docs/4.2/templates It says that giving this layout:

<!-- Stored in app/views/layouts/master.blade.php -->

<html>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show

        <div class="container">
            @yield('content')
        </div>
    </body>
</html>

按此视图扩展

@extends('layouts.master')

@section('sidebar')


    <p>This is appended to the master sidebar.</p>
@stop

@section('content')
    <p>This is my body content.</p>
@stop

将附加到第sidebar节.但实际上,如果你try 是它不附加,它只是override从扩展模板的内容.

我听说其他Blade 的功能是@append, @prepend, @parent.似乎没有人在工作.

另外,官方文档中的这个例子不起作用,我发现Blade 文档很差.比方说,Blade 式服务器的功能与@parent没有什么不同.

推荐答案

documentation from Laravel website中的示例似乎确实有缺陷,但我认为这是网站上的一个markdown 解析问题,same docs on github显示了正确的代码:

无论如何,@parent确实起作用了.文档中的示例应该如下所示:

@extends('layouts.master')

@section('sidebar')
    @parent

    <p>This is appended to the master sidebar.</p>
@stop

@section('content')
    <p>This is my body content.</p>
@stop

A quick look in the Illuminate/View/Factory.php confirms what @parent does:

/**
 * Append content to a given section.
 *
 * @param  string  $section
 * @param  string  $content
 * @return void
 */
protected function extendSection($section, $content)
{
    if (isset($this->sections[$section]))
    {
        $content = str_replace('@parent', $content, $this->sections[$section]);
    }

    $this->sections[$section] = $content;
}

Laravel相关问答推荐

为什么使用 created_at 表在迁移错误中创建表?

如何计算具有特定 ID Laravel 的行

Laravel API 版本控制文件夹 struct

Laravel 5 如何全局设置 Cache-Control HTTP 标头?

调用未定义的函数 App\Http\Controllers\ [函数名]

Laravel 合集日期比较

在 laravel 如何将额外的数据传递给 mutators 和 accessors

Laravel 将 JSON 转换为数组?

如何比较laravel中的两个加密(bcrypt)密码

Laravel Eloquent Pluck 不丢失密钥

Laravel excel maatwebsite 3.1 导入,excel 单元格中的日期列返回为未知格式数字.如何解决这个问题?

如何在 Laravel 中将秒转换为天小时分钟

Laravel Nova - 重新排序左侧导航菜单项

Laravel 说 Auth guard [] 没有定义

Laravel 5 干预中的图像验证

如何调试 Laravel 框架?

Laravel - 语法错误,文件意外结束

Laravel 4 验证唯一(数据库)忽略当前

如何在 Laravel 5.2 中使用 OR 条件将多个参数传递给中间件

Laravel 数据迁移