[英]Laravel Blade: passing a variable to a child view
I have two views 我有两个观点
index and content 索引和内容
The index the view that is returned to via a controller 索引通过控制器返回的视图
return view();
In the index view I was able to echo out aa variable I passed it. 在索引视图中,我能够回显出我传递给它的变量。
When cleaning the file I tried creating a second view content and including that view in from within the index 清理文件时,我尝试创建第二个视图内容,并在索引中包含该视图
yield('content')
How can I pass a variable to content ? 如何将变量传递给内容 ?
Try @include('content')
instead. 请尝试使用
@include('content')
。
This will include the file and all variables already available will automatically be made available in that view. 这将包括该文件,所有已有的变量将自动在该视图中可用。
如果在index
视图中定义了$variable
,并且content
视图扩展了index
,则可以在content
视图中执行此操作:
@extends('index', ['variable' => $variable] )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.