Php Laravel视图、布局和变量传输
我的laravel视图结构如下所示:Php Laravel视图、布局和变量传输,php,view,laravel,blade,Php,View,Laravel,Blade,我的laravel视图结构如下所示: /views/layouts/default.blade.php 包含 <html> @yield('header') <body> @yield('navigation') @yield('content') @yield('footer') </body> 在我的标题视图中,我有一个var$标题 我正在尝试将其动态设置为主页上的控制器 因此在我的视图中位于/pages/index.blad
/views/layouts/default.blade.php
包含
<html>
@yield('header')
<body>
@yield('navigation')
@yield('content')
@yield('footer')
</body>
在我的标题视图中,我有一个var$标题
我正在尝试将其动态设置为主页上的控制器
因此在我的视图中位于/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 var应该通过控制器传递,但我不能这样做:(
我尝试了这个,但没有成功。$title在header partials视图中未定义
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');
}
在Laravel的刀片模板引擎中,您可以使用
@render
或@include
来渲染视图
但是,如果使用@render
,渲染视图将不会从当前视图继承数据。因此,如果需要继承变量等,则需要使用@include
。有关详细信息,请参阅
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');
}