Laravel 4如何使用刀片母版页面将标题和元信息应用于每个页面

Mit*_*enn 28 html php laravel blade laravel-4

试图将个人标题和元描述应用到我的网站页面,但我不确定我尝试的方式是否非常干净.

master.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <title>{{ $title }}</title>
    <meta name="description" content="{{ $description }}">
</head>
Run Code Online (Sandbox Code Playgroud)

个人页面

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

@section('content')
Run Code Online (Sandbox Code Playgroud)

我觉得这是一种快速而肮脏的方式来完成工作,是否有更简洁的方法?

zec*_*ude 86

这也有效:

master.blade.php

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

个人页面

@extends('layouts.master')

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

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

@section('content')
Run Code Online (Sandbox Code Playgroud)

或者如果你想缩短那些,可以这样做:

个人页面

@extends('layouts.master')

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

@section('content')
Run Code Online (Sandbox Code Playgroud)


Ant*_*iro 8

这应该工作:

@extends('layouts.master')
<?php View::share('title', 'title'); ?>

...
Run Code Online (Sandbox Code Playgroud)

你也可以这样做:

@extends('views.coming-soon.layout', ['title' => 'This is an individual page title'])
Run Code Online (Sandbox Code Playgroud)