3

私の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');

    }
4

1 に答える 1

1

Laravel の Blade テンプレート エンジンでは、@renderまたは@includeを使用してビューをレンダリングできます。

ただし、 を使用する@renderと、レンダリングされたビューは現在のビューからデータを継承しません。したがって、変数などを継承する必要がある場合は、 を使用する必要があります@include。詳細については、テンプレート化に関するドキュメントを参照してください。

于 2013-04-03T15:28:03.163 に答える