How to add dynamic page title in Laravel view

Updated at 15-Nov-2021, By samar

How to add dynamic page title in Laravel view

Hello everyone, in this post we will examine how to solve the "How to add dynamic page title in Laravel view" programming puzzle.

You can add dynamic page title in Laravel view while extending layout file. You can use @yield() directive in parent layout view file and @section in child view file to add the dynamic page title to every page in Laravel project.
  • Add dynamic page title to view file while extending layout file in Laravel

    //resources\views\<home>.blade.php
    @extends('layouts.default') 
    @section('title') {{'Lorem ipsum'}} @endsection
    
    //resources\views\layouts\<default>.blade.php
    <!DOCTYPE html>
    <html lang="en">
    <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title> @yield('title') - App</title>
    

    If you want to add dynamic title to the page while extending the layout file, you can use this code snippet.

Back to code snippet queries related laravel