0

我正在尝试在模板(master.blade.php)中包含一个模板(widget.blade.php),如下所示。两个模板都使用名为“内容”的部分,但小部件输出使用来自主文件的内容而不是小部件内容。

大师之刃.php

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>
            @section('title')
            @show
        </title>
    </head>
    <body>
        <div>
            @section('content')
            @show
        </div>

        <div>
            @section('sidebar')
            @show
        </div>
    </body>
</html>

小部件.blade.php

<div class="widget">
    @section('content')
    @show
</div>

index.blade.php

@extends('master')

@section('content')
    Main Content
@stop



@section('sidebar')
    @include('mywidget')
@stop

mywidget.blade.php

@extends('widget')
@section('content')
My Widget Content
@stop

最终结果

Main Content
Main Content

任何想法如何解决这种碰撞?

4

1 回答 1

1

这可以通过使用 @overwrite 而不是 @stop 来解决

@extends('widget')
@section('content')
My Widget Content
@overwrite

来源: http: //laravel.com/docs/templates#other-blade-control-structures

于 2013-10-04T21:53:26.837 回答