R
R
Roman2019-03-30 22:08:58
Laravel
Roman, 2019-03-30 22:08:58

What are the best practices for creating separate titles for each page in Laravel?

Hello.
My first Laravel project is nearing completion :) when suddenly I remembered that we need custom title (and other meta tags) for each page.
But the problem is that the
entire head is placed in layouts.main, and the content is created by a dozen different controllers (this is the specifics of the project) whose methods return views that inherit this same layouts.main - and it turns out that I cannot set a variable from controllers, say, $title, in layouts.main
Or can I?
How is this generally done in the mind usually in Laravel?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jazzus, 2019-03-30
@procode

I did this
in the views, the title variable is passed

extends('layouts.main', ['title' => 'Тайтл'])
@section('content')
//контент
@endsection

in the template, if it exists, it is displayed
<title>
@isset($title)
    {{ $title }} |
@endisset
 {{ config('app.name') }}
</title>

A
Alexander Pushkarev, 2019-03-30
@AXP-dev

Just take any package and do not invent bicycles. An example of what you can connect without racking your brains - https://github.com/eusonlito/laravel-Meta

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question