我正在尝试设置并返回附加到控制器的布局。我可以成功设置@yeild('content')的内容,但我不能同时设置和返回模板。我可以返回模板,没有设置内容,或者我可以返回设置内容,没有布局模板。
master.blade.php
<html>
<head>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
@yield('styles')
</head>
<body>
<div class="container">
<h1>Google Earth project!</h1>
<a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
<hr>
<h4>Content</h4>
@yield('content')
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
@yield('scripts')
</body>
</html>
HotspotController.php
...
public function show($uid, $lid, $hid)
{
// $this->layout->content = View::make('hotspot.profile');
$this->layout->content = 'a string';
return $this->layout;
}
....
答案 0 :(得分:1)
@yield('content')和{{$ content}}之间显然存在差异。
为了完成您要完成的任务,您必须使用后一种方法在刀片模板上声明可变内容。
<强> HotspotController.php 强>
protected $layout = 'layouts.master';
...
public function show($uid, $lid, $hid)
{
$this->layout->content = View::make('hotspot.profile');
}
...
<强> hotspot.profile.blade.php 强>
I am a hotspot profile
<强> master.blade.php 强>
<html>
<head>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
@yield('styles')
</head>
<body>
<div class="container">
<h1>Google Earth project!</h1>
<a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
<hr>
<h4>Content</h4>
{{ $content }}
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
@yield('scripts')
</body>
</html>
<强>另外... 强>
您可以在主模板中保留@yield('content'),但您必须修改hotspot.profile.blade.php以合并@section('content')@stop。请参阅hotspot.blade.php
<强> master.blade.php 强>
<html>
<head>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
@yield('styles')
</head>
<body>
<div class="container">
<h1>Google Earth project!</h1>
<a href="http://laravel.com/docs/quick">Saucey sauce for laravel</a>
<hr>
<h4>Content</h4>
@yield('content')
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
@yield('scripts')
</body>
</html>
<强> hotspot.profile.blade.php 强>
@section('content')
I am a hotspot profile
@stop