laravel 5.4 如何使页面标题动态化
laravel 5.4 how to make page title with dynamic
我有办法获得艺术家的首字母。
这是我的路线
Route::get('/artists/{letter}', 'HomeController@showArtist')->where('letter', '[A-Za-z]+')->name('list');
这是我的控制器 showArtist 方法
public function showArtist($letter){
$artists = Artist::where('name', 'like', $letter.'%')->get();
return view('front.list',compact('artists'));
}
我想要的是在我的列表页面中按字母顺序列出所有艺术家,我制作了这样的字母菜单 A B C,例如,如果单击它,它将获得所有首字母为 A 的艺术家。
但我的问题是如何在我的页面标题中制作像这样的 foreaxmple "Artists begging with letter A" 等
@section('title', 'artists begging with'.$artist->letter)
我的问题是如何找到字母值?
请帮忙如何完成这个?
您可以像这样将选定的字母值传递给 Blade 视图:
return view('front.list',compact('artists','letter'));
而不是:
return view('front.list',compact('artists'));
现在在您看来您可以使用:
<title>Artists begging with {{ $letter }}</title>
如果下面是您的主页标题
<head>
<title>App Name - @yield('title')</title>
</head>
然后您的页面标题可以在您的 blade 页面中更改,如下所示
@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
第一步:在 header 标签中添加此代码。
<title> Website Name ( optional ) - @yield('title')</title>
第二步:在动态页面中添加以下代码。
@section('title', $data['metaTitle'])
我有办法获得艺术家的首字母。
这是我的路线
Route::get('/artists/{letter}', 'HomeController@showArtist')->where('letter', '[A-Za-z]+')->name('list');
这是我的控制器 showArtist 方法
public function showArtist($letter){
$artists = Artist::where('name', 'like', $letter.'%')->get();
return view('front.list',compact('artists'));
}
我想要的是在我的列表页面中按字母顺序列出所有艺术家,我制作了这样的字母菜单 A B C,例如,如果单击它,它将获得所有首字母为 A 的艺术家。
但我的问题是如何在我的页面标题中制作像这样的 foreaxmple "Artists begging with letter A" 等
@section('title', 'artists begging with'.$artist->letter)
我的问题是如何找到字母值?
请帮忙如何完成这个?
您可以像这样将选定的字母值传递给 Blade 视图:
return view('front.list',compact('artists','letter'));
而不是:
return view('front.list',compact('artists'));
现在在您看来您可以使用:
<title>Artists begging with {{ $letter }}</title>
如果下面是您的主页标题
<head>
<title>App Name - @yield('title')</title>
</head>
然后您的页面标题可以在您的 blade 页面中更改,如下所示
@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
第一步:在 header 标签中添加此代码。
<title> Website Name ( optional ) - @yield('title')</title>
第二步:在动态页面中添加以下代码。
@section('title', $data['metaTitle'])