问题
I need to pass a variable to an included Blade file. I have attempted this two-ways; however, neither have been successful.
Pass a variable,
title
, to the included file:@section('left') @include('modal', ['title' => 'Hello']) @stop
Use
@yield
and set the section:@section('left') @include('modal') @section('title') Hello @stop @stop
I am using Laravel 4.2. I am unaware if what I am trying to do is possible, but I imagine it is.
回答1:
According to the documentation, the include
-way should be the way to do it:
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. Just for troubleshooting, try temporarily calling it something else.
回答2:
pass an array of data to the included view
@include('view.name', array('some'=>'data'))
then use this on view/name folder
{{ $some }}
来源:https://stackoverflow.com/questions/33938362/laravel-blade-pass-variable-via-an-include-or-yield