【发布时间】: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