Laravel Blade - pass a variable via @include or @yield

I need to pass the variable to the attached Blade file. I tried to do this in two ways; however, none of them were successful.

  • Pass the title variable 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 do not know that what I am trying to do is possible, but I think it is.

+6
source share
2 answers

According to the documentation , the include -way path should be like this:

Including subviews

@include('view.name')

You can also pass the data array to the included view:

@include('view.name', array('some'=>'data'))

My guess is that $title contradicts another variable in your nested templates. To troubleshoot, try temporarily calling it something else.

+7
source

pass an array of data to the included view

 @include('view.name', array('some'=>'data')) 

then use this in the view / name folder

 {{ $some }} 
+2
source

All Articles