1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel最低限これだけは押さえたいブレードの共通化方法

Posted at

自分の勉強メモ用です。

雛形を作っておく

/resources/views/layout/common.blade.php

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>@yield('title')</title>
</head>
<body>
    @yield('content')
</body>
</html>

@yield('title')@yield('content')のように表示内容を変えたい部分を変数的な感じでyieldを埋めておく

実際に呼び出す側のファイル

/resources/views/index.blade.php

// 呼び出す雛形を@extendsで指定する。
// ディレクトリが違うのは「.」で繋げて指定する
@extends('layout.common')

// 表示内容を変えたい変数部分は@sectionで指定する
@section('title', 'インデックスページ')

@section('content')
    <h1>このページはインデックスページです。</h1>
    <p>ダミーダミーダミー</p>
@endsection
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?