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. --}}

Laravel 4 Blade模板引擎的更多相关文章

  1. laravel Blade 模板引擎

    与视图文件紧密关联的就是模板代码,我们在视图文件中通过模板代码和 HTML 代码结合实现视图的渲染.和很多其他后端语言不同,PHP 本身就可以当做模板语言来使用,但是这种方式有很多缺点,比如安全上的隐 ...

  2. PHP laravel 5.0 Blade 模板引擎 Api使用备注

    PHP laravel 5.0 Blade 模板引擎 Api使用备注 /** * PHP laravel 5.0 Blade 模板引擎 Api使用备注 **/ //子模版中开头,调用@extends( ...

  3. Laravel 5.2 三、中间件、视图与 Blade 模板引擎

    一.中间件 Laravel 的 HTTP 中间件提供了对路由的一层过滤和保护.下面模拟一下用中间件验证后台登录. 1. 创建中间件 cmd 窗口进入项目目录,使用 artisan 命令创建 php a ...

  4. Laravel 5.1 Blade模板引擎

    为什么要使用blade 它是干什么用的? blade模板引擎使我们写HTML页面的地方,使用它是因为它能给我们提供很多的遍历,减少代码的重复率 提高开发效率.我们写blade的路径是 resource ...

  5. 为 Blade 模板引擎添加新文件扩展名

    因为一些原因,我准备把 Blessing Skin 的框架换成 Laravel 了(之前是自己搭建的一个框架),但是在模板迁移的时候遇到了一点问题. 之前我是使用的 XiaoLer/blade 这个从 ...

  6. PHP 安全三板斧:过滤、验证和转义之转义篇 & Blade模板引擎避免XSS攻击原理探究

    PHP 转义 实现 把输出渲染成网页或API响应时,一定要转义输出,这也是一种防护措施,能避免渲染恶意代码,造成XSS攻击,还能防止应用的用户无意中执行恶意代码. 我们可以使用前面提到的 htmlen ...

  7. laravel框架总结(二) -- blade模板引擎

    ## 1.基本用法 ##情形1 $name = laravel5 <div class="title"> {{$name}} {{$name}}</div> ...

  8. laravel框架之blade模板引擎

    ## 1.基本用法 ##情形1 $name = laravel5 <div class="title"> {{$name}} {{$name}}</div> ...

  9. Laravel之视图和Blade模板引擎

    一.视图 1.视图文件存放在resources/views目录2.视图载入及传参 return view('greeting', ['name' => 'James']); 还可以通过with ...

随机推荐

  1. Ubuntu 14.04 下手动安装Firefox的Flash插件

    有时候我们不得不採用手动安装一些软件. Ubuntu 14.04 下手动安装Firefox的Flash插件有下面几步 1. 下载Flash插件 下载地址为http://get.adobe.com/cn ...

  2. Linux驱动开发常用头文件

    头文件目录中总共有32个.h头文件.其中主目录下有13个,asm子目录中有4个,linux子目录中有10个,sys子目录中有5个.这些头文件各自的功能如下: 1.主目录 <a.out.h> ...

  3. OD: Exploit Me - Inject Instruction

    修改之前的代码: #include<stdio.h> #include<stdlib.h> #include<string.h> #include<windo ...

  4. Neral的前言

    大家好,我是Neral,我准备写一个js库. 在动笔之前,我一直都处在很忐忑的状态,因为我写代码讲究的是一种感觉,那是看到自己写的代码之后大脑中就出现之后的无数个编码分支的快感,但是,如果很长一段时间 ...

  5. NodeJs获取不到POST参数

    NodeJs报错,从网页端获取不到POST参数,提示错误类似如下 TypeError: Cannot read property 'username' of undefined     at C:\U ...

  6. java下DataInputStream与DataOutputStream写入数据的同时写入数据类型

    package cn.stat.p2.demo; import java.io.DataInputStream; import java.io.DataOutputStream; import jav ...

  7. uva 688 - Mobile Phone Coverage

    经典问题,矩形面积并. 解法:一.矩形分割,每个矩形的两个横坐标和两个纵坐标排序,这样得到2n*2n个区间,对这些区间依次判断是否包含在n个矩形中间即可.      二.扫描线.具体还没实现过. 详见 ...

  8. $().text() 和 $().html()

    1:性能 stackflow:http://stackoverflow.com/questions/1910794/what-is-the-difference-between-jquery-text ...

  9. Javascript获取某个月的天数-简单方法 .(转别人的)

    Javascript里面的new  Date("xxxx/xx/xx")这个日期的构造方法有一个妙处,当你传入的是"xxxx/xx/0"(0号)的话,得到的日期 ...

  10. DEDE首页调用{dede:field.content/}

    过滤DEDE后台自己添加的Class文件和HTML代码: {dede:sql sql='Select content from #@__arctype where id=1'} [field:cont ...