私のlaravelビュー構造は次のようなものです:
/views/layouts/default.blade.php
含む
<html>
@yield('header')
<body>
@yield('navigation')
@yield('content')
@yield('footer')
</body>
に続いて
/views/partials/footer.blade.php
/views/partials/header.blade.php
/views/partials/navigation.blade.php
私のヘッダービューには var $title があり、ホームページのコントローラーを介して動的に設定しようとしています。
/pages/index.blade.php にある私のビューでは、これを取得しました
@layout('layouts.default')
@section('header')
@render('partials.header')
@endsection
@section('navigation')
@render('partials.menu')
@endsection
@section('footer')
footer
@endsection
@section('content')
@endsection
タイトル変数をコントローラーに渡す必要があることをどこかで読みましたが、できません:(
私は成功せずにこれを試しました.$titleはヘッダーパーシャルビューで定義されていません..
class Home_Controller extends Base_Controller {
public $layout = 'layouts.default';
public function action_index()
{
$this->layout->nest('header', 'home.index')->with('title', 'James');
$posts = Post::with('author')->all();
return View::make('home.index');
}