blade

5316 ワード

テンプレート出力


きほんしゅつりょく

<!-- app/views/example.blade.php --><p>{{ date('d/m/y') }}</p>

げんじしゅつりょく

<!-- app/views/example.blade.php --><p>{{{ '<script>alert("CHUNKY BACON!");</script>' }}}</p>

特殊文字列は自動的にエスケープされ、最終的な結果は次のとおりです.
<!-- app/views/example.blade.php --><p><script>alert("CHUNKY BACON!");</script></p>

せいぎょこうぞう


if

<!-- app/views/example.blade.php -->@if ($something == 'Red Panda')    <p>Something is red, white, and brown!</p>@elseif ($something == 'Giant Panda')    <p>Something is black and white!</p>@else    <p>Something could be a squirrel.</p>@endif

foreach

<!-- app/views/example.blade.php -->@foreach ($manyThings as $thing)    <p>{{ $thing }}</p>@endforeach

for

<!-- app/views/example.blade.php -->@for ($i = 0; $i < 999; $i++)
    <p>Even {{ $i }} red pandas, aren't enough!</p>@endfor

while

<!-- app/views/example.blade.php -->@while (isPretty($kieraKnightly))    <p>This loop probably won't ever end.</p>@endwhile

unless

<!-- app/views/example.blade.php -->@unless (worldIsEnding())    <p>Keep smiling.</p>@endunless

テンプレート参照

<html lang="en"><h1>When does the Narwhal bacon?</h1><!-- app/views/footer.blade.php --><small>Information provided based on research as of 3rd May '13.</small><!-- app/views/example.blade.php --><!doctype html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Narwhals</title></head><body>
    @include('header')    <p>Why, the Narhwal surely bacons at midnight, my good sir!</p>
    @include('footer')</body></html>

テンプレートの継承

<html lang="en"><!doctype html><html lang="en"><head>
    <meta charset="UTF-8">
    <title></title>
    @section('head')        <link rel="stylesheet" href="style.css" />
    @show</head><body>
    @yield('body')
    @section('message')
        @parent        <p>parent message.</p>
    @show</body></html><!-- app/views/home.blade.php -->@extends('layouts.base')
@section('head')    <link rel="stylesheet" href="another.css" />@stop
@section('body')    <h1>Hurray!</h1>
    <p>We have a template!</p>@stop
@section('message')
    @parent    <p>Fourth</p>@stop

テンプレートコメント

{{-- This is a pretty, and secret Blade comment. --}} {{ $var }}  - Echo content {{ $var or 'default' }}  - Echo content with a default value {{{ $var }}}  - Echo escaped content {{-- Comment --}}  - A Blade comment @extends('layout')  - Extends a template with a layout @if(condition)  - Starts an if block @else  - Starts an else block @elseif(condition)  - Start a elseif block @endif  - Ends a if block @foreach($list as $key => $val)  - Starts a foreach block @endforeach  - Ends a foreach block @for($i = 0; $i < 10; $i++)  - Starts a for block @endfor  - Ends a for block @while(condition)  - Starts a while block @endwhile  - Ends a while block @unless(condition)  - Starts an unless block @endunless  - Ends an unless block include(file)  - Includes another template @include(file, ['var' => $val,...])  - Includes a template, passing new variables. @each('file',$list,'item')  - Renders a template on a collection @each('file',$list,'item','empty') - Renders a template on a collection or a different template if collection is empty. @yield('section')  - Yields content of a section. @show  - Ends section and yields its content @lang('message')  - Outputs message from translation table @choice('message', $count)  - Outputs message with language pluralization @section('name')  - Starts a section @stop  - Ends section @endsection  - Ends section @append  - Ends section and appends it to existing of section of same name @overwrite  - Ends section, overwriting previous section of same name