问题描述
我有layouts.app.blade.php,其中有我的<html>
和<body>
标签以及<nav>
.
在<body>
中,我为每个页面生成内容,因此它们基本上扩展了此app.blade.php.
所有Laravel的基本知识,所以现在我有了:
I have layouts.app.blade.php where I have my <html>
and <body>
tags and also the <nav>
.
In the <body>
I yield content for every page, so they basically extend this app.blade.php.
All basic Laravel stuff so now I have this:
<div class="navbar-header">
<!-- Collapsed Hamburger -->
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#spark-navbar-collapse">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Branding Image -->
<a class="navbar-brand" href="/">
*Dynamic page title*
</a>
</div>
// ...
@yield('content')
我想使用此<a class="navbar-brand">
来显示我的页面标题.因此,这意味着必须为在此"parent.blade.php"中加载的每个模板(带有@yield('content'))进行更改.
And I would like to use this <a class="navbar-brand">
to display my pagetitle. So this means it has to change for each template that is loaded (with @yield('content')) in this 'parent.blade.php'.
我如何使用Laravel 5.2做到这一点?
How would I do this using Laravel 5.2?
非常感谢
推荐答案
如果这是您的下面的母版页标题
If this is your master page title below
<html>
<head>
<title>App Name - @yield('title')</title>
</head>
<body>
@section('sidebar')
This is the master sidebar.
@show
<div class="container">
@yield('content')
</div>
</body>
然后可以在刀片页面中更改页面标题,如下所示
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
更多信息可在此处找到 Laravel文档
More information can be found here Laravel Docs
这篇关于导航栏品牌中的Laravel动态页面标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!