bradsi
6/21/2019 - 5:35 PM

Blade Layout Files

Laravel - Blade Layout Files

Blade Layout Files


  • View Layer
  • Blade is Laravel's templating engine
  • Layout files DO NOT replace include/require

Intro


problem: Editing the same element across different pages requires multiple edits to be made.
solution: Blade layout files.

Create New Layout


  1. Create layout file e.g. layout.blade.php
  2. Use yield keyword as placeholder for dynamic content i.e. @yield('content')

Using a Layout


  1. Create new file e.g. index.blade.php
  2. Use extends keyword i.e. @extends('layout')
  3. Use section keyword for dynamic content i.e. @section('content')
  4. Close with endsection keyword i.e. @endsection

An inline section can be used which removes the need for @endsectioni.e. @section('content', '<h1>Contact Us</h1>') i.e. @section('title', 'Contact Us')