qwaz
qwaz

Reputation: 1305

laravel @yield does not work in @include

I need to add class to an included part of html

/* file1.blade.php */

<div class="@yield('myclass')"></div>


/* file2.blade.php */

@include('file1')
@section('myclass', 'foo')

But @yield does not seem to work for @includes. Is there any other way to accomplish this? I cannot use @extends as it breaks the page.

Upvotes: 1

Views: 594

Answers (1)

Ravan Scafi
Ravan Scafi

Reputation: 6392

You can use a simple variable to be your class, and pass it in your include, as the second parameter.

/* file1.blade.php */

<div class="{{ $myClass }}"></div>


/* file2.blade.php */

@include('file1', ['myClass' => 'foo'])

Upvotes: 1

Related Questions