Layouts

Layouts with Template Inheritance

In the older layout style, the layout marks holes with @yield('name', 'default') or with a @section ... @show block of default content, and a page names its parent with @extends and fills the holes with @section, where @parent keeps the layout's content:

Excerpts of layouts/app.blade.php and products/show.blade.phpHTML
<title>@yield('title', 'Bookshop')</title>
@section('nav')
  <nav><a href="/products">All books</a></nav>
@show
@yield('content')
@extends('layouts.app')
@section('title', $product->title)
@section('nav')
  @parent
  <p>Free shipping over {{ $freeShipping }}</p>
@endsection
Output
$ curl -s localhost:8306/products/2 | sed -n '/<title>/p;/<nav>/,/<h1>/p'
  <title>Designing Data-Intensive Applications</title>
            <nav><a href="/products">All books</a></nav>
      <p>Free shipping over $75</p>
      <h1>Designing Data-Intensive Applications</h1>

Blade renders the child first, buffering its sections, then the layout, so text outside any section (STRAY TEXT in a test page) printed before <!doctype html>.