2017/09/02 2019/12/23
Laravelのテンプレートエンジンは標準でBladeというエンジンを使用しています。このテンプレートエンジンは比較的よくあるテンプレートエンジンの記法に近いのですんなり覚える事ができると思います。bladeもまたよくあるテンプレートエンジン同様にマスターレイアウトがあって、その上にパーツ&ブロック単位のテンプレートがある仕組みになっています。ヘッダとフッタはよくある共通部分ですから簡単振り分けて構築できそうです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<html> <head> <title>@yield('title')</title> </head> <body> @section('sidebar') This is the master sidebar. @show <div class="container"> @yield('content') </div> </body> </html> ~ |
ちょっと見た感じでは他のテンプレートよりも見たことがないインクルードする幾つもの記法があることがわかりますね。マスターレイアウトはアウトラインを作るものです。
それでは次にHTMLのBODY部分を形成するテンプレートを見てみましょう。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
@extends('layouts.master') @section('title', 'Page Title') @section('sidebar') <p>This is appended to the master sidebar.</p> @endsection @section('content') <p>This is my body content.</p> @endsection |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?php /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/', function () { return view('welcome'); }); /* Route::get('/hello',function(){ return 'Hello World!'; });*/ Route::get('/hello', 'Hello@index'); Route::get('/hello/{name}', 'Hello@show'); Route::get('/blade', function () { return view('page'); }); |