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>
个人页面
@extends('layouts.master')
<?php $title = "This is an individual page title"; ?>
<?php $description = "This is a description"; ?>
@section('content')
我觉得这是一种快速而肮脏的方式来完成工作,是否有更简洁的方法?
zec*_*ude 86
这也有效:
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'])