Trying to apply an individual title and meta description to my websites pages, but I'm not sure if the way I'm attempting is very clean.

master.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <title>{{ $title }}</title>
    <meta name="description" content="{{ $description }}">
</head>

individual page

@extends('layouts.master')
<?php $title = "This is an individual page title"; ?>
<?php $description = "This is a description"; ?>

@section('content')

我觉得这是一种又快又脏的方法来完成这项工作,有没有更干净的方法?

推荐答案

This works as well:

master.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <title>@yield('title')</title>
    <meta name="description" content="@yield('description')">
</head>

individual page

@extends('layouts.master')

@section('title')
    This is an individual page title
@stop

@section('description')
    This is a description
@stop

@section('content')

或者,如果你想再缩短一点,也可以这样做:

individual page

@extends('layouts.master')

@section('title', 'This is an individual page title')
@section('description', 'This is a description')

@section('content')

Laravel相关问答推荐

无法在终端cPanel中打开输入文件:artisan

在没有lang/*.json文件的情况下在Laravel项目中实现多语言支持

用Laravel Filament创建变形组件

自定义验证在表单请求上始终返回 true laravel

在Laravel中URL中添加保护ID

我如何通过 laravel 在高图中针对不同的时间范围进行烛台数据分组

Laravel Eloquent:组合列(或自定义属性)上的 Where 子句

FileViewFinder.php 第 137 行中的 Laravel 5 InvalidArgumentException:未找到视图 [.admin]

验证规则 required_if 与其他条件(Laravel 5.4)

Laravel 中未加密的 cookie

如何在 Laravel 中创建类别的嵌套列表?

Laravel 控制器构造

约定表名(带下划线)

在 Laravel 中将 Eloquent 导出到 Excel 时如何包含列标题?

Laravel 5 - 判断日期是否是今天

Laravel 获取查询字符串

Laravel 5 事件处理程序未触发

Laravel 中的 isDirty() 是什么意思?

使用 Laravel Mix 合并多个文件

如何从 laravel 5.1 中数据库表的 created_at 属性中 Select 年份和月份?