zoukankan      html  css  js  c++  java
  • 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. --}}
  • 相关阅读:
    一个Netfilter nf_conntrack流表查找的优化-为conntrack添加一个per cpu cache
    【翻译自mos文章】检查$ORACLE_HOME是否是RAC的HOME的方法以及relink RAC的Oracle binary的方法
    DVBS/S2在数字电视系统中的应用 三 (LNB介绍)
    cache数据库之表的存储结构
    jsp网页在浏览器中不显示图片_eclipse环境下配置tomcat中jsp项目的虚拟路径
    彻底搞懂oracle的标量子查询
    OpenCV学习教程入门篇&lt;一、介绍&gt;
    NYOJ 38 布线问题_(解法1 Kruskal算法)
    HTML5之WebSocket && https://zhuanlan.zhihu.com/p/23467317
    HTML5离线缓存
  • 原文地址:https://www.cnblogs.com/fx2008/p/3572957.html
Copyright © 2011-2022 走看看