テンプレート出力
きほんしゅつりょく
<!-- 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. --}}