Srashti sharma
Srashti sharma

Reputation: 57

How To Add Title For Each Page In Laravel

In my laravel website all pages having same title meta but how to make different title for each page please tell me.

this is my code for dynamic showing in all the pages

<title>{{setting('site.title')}} | {{setting('site.description')}}  @if(isset($data->title)) {{$data->title}} @endif</title>

file name is layouts/app.blade.php

Upvotes: 4

Views: 12787

Answers (5)

Kul
Kul

Reputation: 210

Inside your app.blade.php,

<head>
  @yield('title')
  ... // other scripts
</head>

For other pages which user app.blade.php you can use it like after extending app.blade.php :

@section('title')
    <title> Your Page Title Here  </title>
@endsection`

Hope it helps. happy coding.

Upvotes: 2

It&#39;s VIN
It&#39;s VIN

Reputation: 312

in your controller

    public function aboutUs()
    {
        //page title
        $title = 'Project | About Us';
        return view('project.about_us', compact('title'));
    }

for your view page

<title>{{ $title }}</title>

Upvotes: 1

Xhuljo
Xhuljo

Reputation: 799

Simply inside your app.blade.php Put this: @yield('title')

In other pages just extend the layout and put the new title at the this section

@extends('layoutWhateverYouNamedIt')

@section('title') Type your title here @endsection

Upvotes: 2

raz tsfaty
raz tsfaty

Reputation: 151

Inside your app.blade.php, in the head section. change:

<title>{{ config('app.name', 'Laravel') }}</title>

to:

<title>@yield('title')</title>

You can choose any name/title that seems fitting. For other views.blade.php pages,(extending app.blade.php) you can add a title this way:

@section('title','My Title')

this comes after @extends('layouts.app')

Upvotes: 15

Kamal Paliwal
Kamal Paliwal

Reputation: 1301

You can specify different title for different views.

In you common header file make your title like this:

<title>@yield('page_title', 'Default Title')</title>

Then in your view file change the title to whatever you want it to be set in following way:

@section('page_title')
    {{ "Your Title" }}
@endsection

Upvotes: 13

Related Questions