Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blade template yield with default include

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.

like image 229
Geoff Avatar asked Jan 11 '15 19:01

Geoff


People also ask

What is yield (' content ') in Laravel?

In Laravel, @yield is principally used to define a section in a layout and is constantly used to get content from a child page unto a master page.

What is it blade template engine package?

The Blade is a powerful templating engine in a Laravel framework. The blade allows to use the templating engine easily, and it makes the syntax writing very simple. The blade templating engine provides its own structure such as conditional statements and loops.

What are benefits of using blade template in Laravel?

In addition to template inheritance and displaying data, Blade also provides convenient shortcuts for common PHP control structures, such as conditional statements and loops. These shortcuts provide a very clean, terse way of working with PHP control structures while also remaining familiar to their PHP counterparts.

Can I use blade template without Laravel?

Yes you can use it where ever you like.


1 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'))
like image 59
lukasgeiter Avatar answered Sep 30 '22 07:09

lukasgeiter