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"中加载的每个模板(带有@Year(‘content’))进行更改.

How would I do this using Laravel 5.2?

Many thanks

推荐答案

如果这是你的主页标题

<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

More information can be found here Laravel Docs

Laravel相关问答推荐

LaravelEloquent 的模型如何将值从控制器内部的函数传递到Render()

在 blade laravel 中以格式编号显示长数字

Laravel Horizo​​n 限制与优化

如何将用户对象绑定到中间件中的请求

Laravel,没有shell 访问的转储自动加载

Laravel 中未加密的 cookie

laravel 中的 Http Post 使用 fetch api 给出 TokenMismatchException

不支持驱动Driver[] - Laravel 5.3

在 Laravel 中将 Public 添加到assets资源路径

413请求实体在laravel homestead for windows中太大的nginx服务器

如何在 Laravel 中实现数组类型路由?

如何从 laravel 中的现有数据库创建迁移

Laravel 分页方法不适用于 map 集合?

Laravel 和 PHPStorm 项目的 gitignore 中包含什么?

调用未定义的方法 Illuminate\Foundation\Application::bindShared()

禁用Eager的关系

扩展模型 == 扩展 Eloquent?

assets资源不引用公用文件夹(Laravel)

无法在控制器的构造函数上调用 Auth::user()

如果在 Laravel 5.1 中找不到路由,则显示 404 页面