Laravel Dynamic Page Title | Set Page Title

shanisingh03

shani singh

Posted on May 30, 2021

Laravel Dynamic Page Title | Set Page Title

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

💖 💪 🙅 🚩
shanisingh03
shani singh

Posted on May 30, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related