• Laravel 4 Blade模板引擎


    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>&lt;script&gt;alert(&quot;CHUNKY BACON!&quot;);&lt;/script&gt;</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>
    6 @else
    7     <p>Something could be a squirrel.</p>
    8 @endif

    foreach

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

    for

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

    while

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

    unless

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

    模板引用

    01 <html lang="en">
    02 <h1>When does the Narwhal bacon?</h1>
    03  
    04 <!-- app/views/footer.blade.php -->
    05 <small>Information provided based on research as of 3rd May '13.</small>
    06  
    07 <!-- app/views/example.blade.php -->
    08 <!doctype html>
    09 <html lang="en">
    10 <head>
    11     <meta charset="UTF-8">
    12     <title>Narwhals</title>
    13 </head>
    14 <body>
    15     @include('header')
    16     <p>Why, the Narhwal surely bacons at midnight, my good sir!</p>
    17     @include('footer')
    18 </body>
    19 </html>

    模板继承

    01 <html lang="en">
    02 <!doctype html>
    03 <html lang="en">
    04 <head>
    05     <meta charset="UTF-8">
    06     <title></title>
    07     @section('head')
    08         <link rel="stylesheet" href="style.css" />
    09     @show
    10 </head>
    11 <body>
    12     @yield('body')
    13     @section('message')
    14         @parent
    15         <p>parent message.</p>
    16     @show
    17 </body>
    18 </html>
    19  
    20 <!-- app/views/home.blade.php -->
    21 @extends('layouts.base')
    22 @section('head')
    23     <link rel="stylesheet" href="another.css" />
    24 @stop
    25 @section('body')
    26     <h1>Hurray!</h1>
    27     <p>We have a template!</p>
    28 @stop
    29 @section('message')
    30     @parent
    31     <p>Fourth</p>
    32 @stop

    模板注释

    1 {{-- This is a pretty, and secret Blade comment. --}}
  • 相关阅读:
    Eclipse中配置Tomcat碰到Server Tomcat v6.0 Server at localhost failed to start问题
    解决java中对URL编码的问题
    上白泽慧音
    小K的农场
    [USACO15JAN]草鉴定Grass Cownoisseur
    [HNOI2012]矿场搭建/Mining Your Own Business
    [POI2008]BLO-Blockade
    「JOISC 2018 Day 1」帐篷
    Sudoku
    序列
  • 原文地址:https://www.cnblogs.com/fx2008/p/3572957.html
Copyright © 2020-2023  润新知