简体   繁体   English

Laravel Blade:将变量传递给子视图

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM