Lavarel5.1入门-Blade模板引擎

  1. Blade视图文件使用.blade.php文件扩展并存放在resources/views目录下。
  2. routes.php
Route::get('/child', function () {
    $records=['a','b','c'];
    return view('layouts/child',[
    'firstStr'=>'hello child h3 firstStr',
    'name'=>'name hello',
    'records'=>$records
]);
});

master.blade.php

@yield('firstStr')

{{ time() }}

{{ isset($name) ? $name : 'Default' }}

@if (count($records) === 1) I have one record! @elseif (count($records) > 1) I have multiple records! @else I don't have any records! @endif

@yield('content')

child.blade.php

@extends('layouts.master')
@section('firstStr')
 {{ $firstStr }}
@endsection
@section('content')
    

This is my body content.

@inject('metrics', 'App\Services\Hello')
Monthly Revenue: {{ $metrics->haha() }}.

@endsection

App/Services/Hello.php

  1. 循环
//
@for ($i = 0; $i < 10; $i++)
    The current value is {{ $i }}
@endfor
//
@foreach ($users as $user)
    

This is user {{ $user->id }}

@endforeach // @forelse ($users as $user)
  • {{ $user->name }}
  • @empty

    No users

    @endforelse // @while (true)

    I'm looping forever.

    @endwhile
    1. 注释
    {{-- This comment will not be present in the rendered HTML --}}
    
    1. 子视图@include
    2. 服务注入

    参考

    Blade模板引擎

    你可能感兴趣的:(Lavarel5.1入门-Blade模板引擎)