我在Laravel中有一个页面系统-我在其中将数据从控制器传递到视图。
$this->data['title'] = $row->title;
$this->data['breadcrumb'] = $row->bc;
现在,我将其传递如下:
return View::make('Themes.Page', $this->data);
在视图文件中,我按以下方式访问数据:
{{$breadcrumb}}
我现在想做的是在嵌套视图中传递此数据:
$this->layout->nest('content',$page, $this->data);
(内容是视图中的{{content}},将被$ page内容替换。我想像以前一样传递$ this-> data,但是现在出现错误:
变量面包屑未定义。
注意:Laravel版本4.2 $ this-> layout在构造函数中设置为模板文件(Themes.Page)
实际上,您不需要将任何单独的数据传递到您的部分页面(面包屑)
$this->data['title'] = $row->title;
$this->data['breadcrumb'] = $row->bc;
return View::make('idea.show',array("data"=>$this->data));
<div>
<h1>here you can print data passed from controller {{$data['title']}}</h1>
@include('partials.breadcrumb')
</div>
<div>
<h1>here also you can print data passed from controller {{$data['title']}}</h1>
<ul>
<li>....<li>
<li>....<li>
</ul>
</div>
有关此的更多信息,您可以查看以下链接http://laravel-recipes.com/recipes/90/includes-a-blade-template-within-another-template或观看此视频https://laracasts.com/series / laravel-5-fundamentals / episodes / 13
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句