1. 程式人生 > >laravel模板機制

laravel模板機制

等價 record content ping page sidebar 引入 endif signed

@extends(‘layouts.master‘)

@section(‘title‘, ‘Page Title‘)

@section(‘sidebar‘)
    @parent
    <p>This is appended to the master sidebar.</p>
@endsection

@section(‘content‘)
    <p>This is my body content.</p>
@endsection
{{ isset($name) ? $name : ‘Default‘ }}  = {{ $name or ‘Default‘ }}  等價
@{{ name }}  直接輸出

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

和IF相反
@unless (Auth::check())
    You are not signed in.
@endunless


@for ($i = 0; $i < 10; $i++)
    The current value is {{ $i }}
@endfor

@foreach ($users as $user)
    <p>This is user {{ $user->id }}</p>
@endforeach

@forelse ($users as $user)
    <li>{{ $user->name }}</li>
@empty
    <p>No users</p>
@endforelse

@while (true)
    <p>I‘m looping forever.</p>
@endwhile

@foreach ($users as $user)
    @if ($loop->first)
        This is the first iteration.
    @endif

    @if ($loop->last)
        This is the last iteration.
    @endif

    <p>This is user {{ $user->id }}</p>
@endforeach



@foreach ($users as $user)
    @foreach ($user->posts as $post)
        @if ($loop->parent->first)
            This is first iteration of the parent loop.
        @endif
    @endforeach
@endforeach


 @include(‘shared.errors‘)


堆棧

Blade允許你推送內容到命名堆棧,以便在其他視圖或布局中渲染。這在子視圖中引入指定JavaScript庫時很有用:

@push(‘scripts‘)
    <script src="/example.js"></script>
@endpush

推送次數不限,要渲染完整的堆棧內容,傳遞堆棧名稱到 @stack 指令即可:

<head>
    <!-- Head Contents -->

    @stack(‘scripts‘)
</head>


{{time()}}

laravel模板機制