@yield directive Laravel

Layouts may be created via "template inheritance". This was the primary way of building applications prior to the introduction of components. Since most web applications maintain the same general layout across various pages, it's convenient to define this layout as a single Blade view.

The @section directive, as the name implies, defines a section of content, while the @yield directive is used to display the contents of a given section.

After defining a layout for our application define a child page that inherits the layout. When defining a child view, use the @extends Blade directive to specify which layout the child view should "inherit". Views which extend a Blade layout may inject content into the layout's sections using @section directives. Remember the contents of these sections will be displayed in the layout using @yield.

The @yield directive also accepts a default value as its second parameter. This value will be rendered if the section being yielded is undefined:

    @yield('content', 'Default content')

back to all posts