Home » Php » Blade template yield with default include

Blade template yield with default include

Posted by: admin November 30, 2017 Leave a comment

Questions:

Is it possible to yield to another view but then default with an include statement?

Example:

@yield('header', @include('partials.header'))

The intended action is that if the subview does not include the header, then the current template will include the partials.header view.

Answers:

It is possible. But you can’t use blade tags inside blade tags. What you can do however is use View::make() instead of @include. @include actually compiles to a make call on the view factory.

@yield('header', View::make('partials.header'))