my laravel view structure is like this:
/views/layouts/default.blade.php
containing
<html>
@yield('header')
<body>
@yield('navigation')
@yield('content')
@yield('footer')
</body>
following by
/views/partials/footer.blade.php
/views/partials/header.blade.php
/views/partials/navigation.blade.php
In my header view i have a var $title I'm trying to set it dynamically trought the controller on the home page.
so in my view located in /pages/index.blade.php I got this
@layout('layouts.default')
@section('header')
@render('partials.header')
@endsection
@section('navigation')
@render('partials.menu')
@endsection
@section('footer')
footer
@endsection
@section('content')
@endsection
I read somewhere that the title var should be passed throught the controller but i can't do it :(
i tried this without any success.$title is undefined in header partials views..
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');
}
In Laravel's Blade templating engine you can use either @render
or @include
to render views.
However, if you use @render
, the rendered view won't inherit data from the current view. So, if you need variables etc. to be inherited, you need to use @include
. See the docs on templating for more information.