DEV Community

loading...
Cover image for Laravel Dynamic Page Title | Set Page Title

Laravel Dynamic Page Title | Set Page Title

shani singh
FullStack Developer, PHP, LARAVEL, VueJs, Angular.
・1 min read

As Laravel use Blade template engine, many time we have to use the page title to be displayed dynamically,

Let's Consider you have a master layout for your app.
which have a structure something like

<html>
<head>
    <title>App Name - @yield('title')</title>
</head>
<body>
    @section('sidebar')
        This is the master sidebar.
    @show

    <div class="container">
        @yield('content')
    </div>
</body>
Enter fullscreen mode Exit fullscreen mode

Here in Master Layout the code for title is.

<title>App Name - @yield('title')</title>
Enter fullscreen mode Exit fullscreen mode

Then You load the Content Page which looks like.

@extends('layouts.master')

@section('title') {{'Page Title Goes Here'}} @endsection

@section('content')
<p>This is my body content.</p>
@endsection
Enter fullscreen mode Exit fullscreen mode

Here in Content file the code for title is.

@section('title') {{'Page Title Goes Here'}} @endsection
Enter fullscreen mode Exit fullscreen mode

You can watch the video below for live coding.

Thank You for Reading

Reach Out To me.
Twitter
Instagram
TechToolIndia

Discussion (0)