[英]Laravel Blade - pass variable via an @include or @yield
I need to pass a variable to an included Blade file. 我需要将变量传递给包含的Blade文件。 I have attempted this two-ways;
我试过这两种方式; however, neither have been successful.
然而,两者都没有成功。
Pass a variable, title
, to the included file: 将变量
title
传递给包含的文件:
@section('left') @include('modal', ['title' => 'Hello']) @stop
Use @yield
and set the section: 使用
@yield
并设置部分:
@section('left') @include('modal') @section('title') Hello @stop @stop
I am using Laravel 4.2. 我正在使用Laravel 4.2。 I am unaware if what I am trying to do is possible, but I imagine it is.
我不知道我想做什么是可能的,但我想是的。
According to the documentation , the include
-way should be the way to do it: 根据文档 ,
include
-way应该是这样做的方式:
Including Sub-Views
包括子视图
@include('view.name')
You may also pass an array of data to the included view:
您还可以将数据数组传递给包含的视图:
@include('view.name', array('some'=>'data'))
My hunch is that $title
is conflicting with another variable in your nested templates. 我的预感是
$title
与嵌套模板中的另一个变量冲突。 Just for troubleshooting, try temporarily calling it something else. 只是为了排除故障,尝试暂时将其称为其他内容。
pass an array of data to the included view 将数据数组传递给包含的视图
@include('view.name', array('some'=>'data'))
then use this on view/name folder 然后在view / name文件夹上使用它
{{ $some }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.