http://my.oschina.net/5say/blog/201290
模板输出
基本输出
1 |
<!-- app/views/example.blade.php --> |
2 |
<p>{{ date( 'd/m/y' ) }}</p> |
原样输出
1 |
<!-- app/views/example.blade.php --> |
2 |
<p>{{{ '<script>alert("CHUNKY BACON!");</script>' }}}</p> |
特殊字符串将被自动转义,最终结果如下:
1 |
<!-- app/views/example.blade.php --> |
2 |
<p><script>alert("CHUNKY BACON!");</script></p> |
控制结构
if
1 |
<!-- app/views/example.blade.php --> |
2 |
@if ($something == 'Red Panda' ) |
3 |
<p>Something is red, white, and brown!</p> |
4 |
@elseif ($something == 'Giant Panda' ) |
5 |
<p>Something is black and white!</p> |
7 |
<p>Something could be a squirrel.</p> |
foreach
1 |
<!-- app/views/example.blade.php --> |
2 |
@foreach ($manyThings as $thing) |
for
1 |
<!-- app/views/example.blade.php --> |
2 |
@for ($i = 0 ; $i < 999 ; $i++) |
3 |
<p>Even {{ $i }} red pandas, aren't enough!</p> |
while
1 |
<!-- app/views/example.blade.php --> |
2 |
@while (isPretty($kieraKnightly)) |
3 |
<p>This loop probably won't ever end.</p> |
unless
1 |
<!-- app/views/example.blade.php --> |
2 |
@unless (worldIsEnding()) |
模板引用
02 |
<h1>When does the Narwhal bacon?</h1> |
04 |
<!-- app/views/footer.blade.php --> |
05 |
<small>Information provided based on research as of 3rd May ' 13 .</small> |
07 |
<!-- app/views/example.blade.php --> |
11 |
<meta charset= "UTF-8" > |
12 |
<title>Narwhals</title> |
16 |
<p>Why, the Narhwal surely bacons at midnight, my good sir!</p> |
模板继承
05 |
<meta charset= "UTF-8" > |
08 |
<link rel= "stylesheet" href= "style.css" /> |
15 |
<p>parent message.</p> |
20 |
<!-- app/views/home.blade.php --> |
21 |
@extends ( 'layouts.base' ) |
23 |
<link rel= "stylesheet" href= "another.css" /> |
27 |
<p>We have a template!</p> |
模板注释
1 |
{{-- This is a pretty, and secret Blade comment. --}} |