laravel 5.4 how to make page title with dynamic
Asked Answered
R

3

10

ihave a route to get artists initial letter.

this is my route

Route::get('/artists/{letter}', 'HomeController@showArtist')->where('letter', '[A-Za-z]+')->name('list');

and this is my controller showArtist method

public function showArtist($letter){
        $artists = Artist::where('name', 'like', $letter.'%')->get();
        return view('front.list',compact('artists'));
    }

what i want is in my list page that lists all artists alphabetically, i have made alphabetical menu like this A B C, FOR example if is clicked it will get all artists with initial letter A.

but my question is how can i make in my page title, foreaxmple like this "Artists begging with letter A" etc.

@section('title', 'artists begging with'. $artist->letter)

my question is how to find letter value?

please help how to accomplish this?

Remarkable answered 12/3, 2017 at 19:36 Comment(0)
M
8

You can pass selected letter value to Blade view like this:

return view('front.list',compact('artists','letter'));

instead of:

return view('front.list',compact('artists'));

And now in your view you can use:

<title>Artists begging with {{ $letter }}</title>
Mansized answered 12/3, 2017 at 19:47 Comment(1)
Perfect it worked as you mentioned. Thank u very much for your helpRemarkable
N
23

If this is your master page title below

<head>
        <title>App Name - @yield('title')</title>
    </head>

then your page title can be changed in your blade page like below

@extends('layouts.master')

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

@section('sidebar')
@parent

<p>This is appended to the master sidebar.</p>
@endsection

@section('content')
<p>This is my body content.</p>
@endsection
Negotiable answered 14/6, 2017 at 13:56 Comment(2)
If the title hasn't been set in your blade page, a dash will awkwardly show at the end of the 'App Name'. If this is a problem for you, use something like this in your master page layout: @if(View::hasSection('title'))@yield('title') - @endif{{ config('app.name', 'Laravel') }}.Muddle
Additionally, if your application supports multiple languages, doing @section('title', 'Page Title') may not be an option. To use Laravel's language translation features with the @section directive simply call trans() like so: @section('title', trans('feature.title')).Muddle
M
8

You can pass selected letter value to Blade view like this:

return view('front.list',compact('artists','letter'));

instead of:

return view('front.list',compact('artists'));

And now in your view you can use:

<title>Artists begging with {{ $letter }}</title>
Mansized answered 12/3, 2017 at 19:47 Comment(1)
Perfect it worked as you mentioned. Thank u very much for your helpRemarkable
A
0

First step : Add this code inside header Tag.

 <title> Website Name ( optional ) - @yield('title')</title>

Second Step : Add below code inside dynamic Page.

@section('title',  $data['metaTitle'])
Arabian answered 22/12, 2020 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.