【问题标题】:laravel template inside template模板内的 laravel 模板
【发布时间】:2013-10-11 22:50:52
【问题描述】:

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

master.blade.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>

widget.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

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

【问题讨论】:

  • 重命名为 'widget.content' 怎么样?
  • 好主意,但是当添加多个 @include('mywidget') 时,覆盖将再次发生,并且会多次看到第一个 mywidget 内容。

标签: php templates laravel laravel-4 blade


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2014-10-26
    • 2020-11-15
    • 1970-01-01
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多