[Laravel] 關於layout (about layout)

繁體中文:

1、新增app/views/layouts資料夾,此資料夾放置相關layout檔案,例:新增default.blade.php這個檔案。
@yield(‘content’)就是其它view檔將會填補的區域。

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>test</title>
  </head>
  <body>
    @yield('content')
    
    @yield("footer")
  </body>
</html>

2、開啟app/views/users/index.blade.php,若沒有該檔,可隨意建立,主要是以下程式碼:
@extends(“layouts.default”):取用layouts/defalut.blade.php這個layout檔
@section(“content”)…@stop:此區域會塞入layout檔裡的@yield(“content”)。

@extends("layouts.default")

@section('content')
  <h1>all users</h1>
  <ul>
    @if($users->count())
      @foreach($users as $user)
        <li>{{ link_to("/users/{$user->username}", $user->username) }}</li>
      @endforeach
    @else
      <p>Unfortunately, there are no users.</p>
    @endif
  </ul>
@stop

@section("footer")

@stop

English Version:

1、new app/views/layouts directory, this directory place some layout files, ex: add default.blade.php file.
@yield(‘content’) is a field that other view file will fill it.

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>test</title>
  </head>
  <body>
    @yield('content')
    
    @yield("footer")
  </body>
</html>

2、open app/views/users/index.blade.php, new it if you have no this file.
@extends(“layouts.default”): use layouts/defalut.blade.php layout file.
@section(“content”)…@stop: This filed will fill in @yield(“content”) of layout file.

@extends("layouts.default")

@section('content')
  <h1>all users</h1>
  <ul>
    @if($users->count())
      @foreach($users as $user)
        <li>{{ link_to("/users/{$user->username}", $user->username) }}</li>
      @endforeach
    @else
      <p>Unfortunately, there are no users.</p>
    @endif
  </ul>
@stop

@section("footer")

@stop