laravel @yield does not work in @include -


i need add class included part of html

/* file1.blade.php */  <div class="@yield('myclass')"></div>   /* file2.blade.php */  @include('file1') @section('myclass', 'foo') 

but @yield not seem work @includes. there other way accomplish this? cannot use @extends breaks page.

you can use simple variable class, , pass in include, second parameter.

/* file1.blade.php */  <div class="{{ $myclass }}"></div>   /* file2.blade.php */  @include('file1', ['myclass' => 'foo'])