laravel 5.4 如何动态制作页面标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42752133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:32:46  来源:igfitidea点击:

laravel 5.4 how to make page title with dynamic

phplaravellaravel-5bladelaravel-5.4

提问by Mahamoud Mahamed

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

这是我的控制器 showArtist 方法

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.

我想要的是在我的列表页面中按字母顺序列出所有艺术家,我已经制作了像这个 ABC 这样的字母顺序菜单,例如,如果点击它会得到所有带有首字母 A 的艺术家。

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

但我的问题是如何在我的页面标题中制作像这样的“艺术家用字母 A 乞讨”等开头。

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

@section('title', '艺术家乞求'。$artist->letter)

my question is how to find letter value?

我的问题是如何找到字母值?

please help how to accomplish this?

请帮助如何做到这一点?

采纳答案by Marcin Nabia?ek

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

您可以像这样将选定的字母值传递给 Blade 视图:

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>

回答by krekto

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