博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Laravel 4 Blade模板引擎
阅读量:6857 次
发布时间:2019-06-26

本文共 2282 字,大约阅读时间需要 7 分钟。

 

模板输出

基本输出

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

转载于:https://www.cnblogs.com/fx2008/p/3572957.html

你可能感兴趣的文章
docker学习系列1 使用docker 快速实现多版本PHP
查看>>
在阿里云做前端,是种怎样的体验?
查看>>
软银重金加注无人货运,9.4亿美元投资机器人公司Nuro
查看>>
Spring Cloud Alibaba基础教程:Nacos的集群部署
查看>>
地铁译:Spark for python developers ---Spark流式数据处理
查看>>
最全技术面试180题:阿里11面试+网易+百度+美团!
查看>>
「镁客·请讲」透彻影像王书浩:用AI“复制”大脑,弥补病理医生的9万缺口...
查看>>
涨姿势,图文带你了解 8 大排序算法
查看>>
Java基础知识的全面巩固_note1(附各种demo code)
查看>>
DataWorks2.0的“业务流程”与1.0的“工作流”的对比
查看>>
基于Kubernetes的容器云在万达的落地
查看>>
阿里联合ICA联盟发布IoT系列标准,智能门锁标准首批授权测试机构名单出炉
查看>>
Fastify 2.2.0 和 1.14.5 发布,极速 Node.js Web 框架
查看>>
vim设置一键执行python代码
查看>>
普通程序员该如何进阶为全栈工程师?
查看>>
WebStorm 开发配置
查看>>
Android动画相关(一)
查看>>
Spring @RequestBody与@ResponseBody注解
查看>>
python之turtle实现‘开花’和签名
查看>>
报表集成那点事
查看>>