试图将个人标题和元描述应用到我的网站页面,但我不确定我尝试的方式是否非常干净。
master.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>{{ $title }}</title>
<meta name="description" content="{{ $description }}">
</head>
个人页面
@extends('layouts.master')
<?php $title = "This is an individual page title"; ?>
<?php $description = "This is a description"; ?>
@section('content')
我觉得这是一种快速而肮脏的方式来完成工作,是否有更简洁的方法?
这也有效:
master.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>@yield('title')</title>
<meta name="description" content="@yield('description')">
</head>
个人页面
@extends('layouts.master')
@section('title')
This is an individual page title
@stop
@section('description')
This is a description
@stop
@section('content')
或者如果你想缩短那些,可以这样做:
个人页面
@extends('layouts.master')
@section('title', 'This is an individual page title')
@section('description', 'This is a description')
@section('content')
这应该工作:
@extends('layouts.master')
<?php View::share('title', 'title'); ?>
...
你也可以这样做:
@extends('views.coming-soon.layout', ['title' => 'This is an individual page title'])
真的推荐这个:
https://github.com/artesaos/seotools
您将信息传递给视图需要的内容
SEOTools::setTitle($page->seotitle);
SEOTools::setDescription($page->seodescription);
没有人认为最好的方法是使用facade(Site :: title(),Site :: description等)和mutators(通过Str :: macro)创建自己的类,自动检查标题,描述等是否格式正确(最大长度,添加类别,默认值,分隔符等)并在必要时将数据克隆到其他字段(title => og:title,description => og:description)?
如果你想在你的标题中使用一个变量,所以它是从你的数据库动态生成的,我这样做:
master.blade.php
<title>@yield('title')</title>
article.blade.php
@section( 'title', '' . e($article->title) )