[李景山php]每天laravel[030]-laravel 基础知识 --- blade模版
2017-04-05 08:56
701 查看
blade 模版使用:
关键点一: .blade.php 文件后缀
关键点二:默认存放位置 resources/views 目录下面
第一: 模版布局之模版集成
1.1 集成模版
extends(‘layouts.master’); 继承这个 模版 ,继承的位置是 resources/views/layouts/master.blade.php 这个模版
1.2 父级模版替换
父级中用 @yield(‘title’);—–>子级中使用 @sestion(‘title’,’this is a title’);
1.3 继承 父级 内容,
父级:
@section(‘main’)
这个是父级的内容
@show
子级:
@section(‘main’)
@@parent
这个是子集的内容
@endsection
解析后的结果就是:
这个是父级的内容
这个是子集的内容
第二:基本数据展示
2.1 变量
2.2 函数
2.3 原样输出
2.4 默认值
2.5 未转义输出
第三:流程控制【结构控制】
3.1 @if() @elseif() @else @endif
3.2 @unless @endunless
3.3 @for() @endfor @foreach() @endforeach @forelse() @endforelse @while() @endwhile
第四:引入视图
@include(‘shared.errors’)
第五:多视图赋值
@each(‘view.name’,$job,’job’,’view.empty’)
第六:依赖注入
第七:自定义模版【扩展blade】
通过在 AppServiceProvider 里面的 boot 函数进行定义如下:
关键点一: .blade.php 文件后缀
关键点二:默认存放位置 resources/views 目录下面
第一: 模版布局之模版集成
1.1 集成模版
extends(‘layouts.master’); 继承这个 模版 ,继承的位置是 resources/views/layouts/master.blade.php 这个模版
1.2 父级模版替换
父级中用 @yield(‘title’);—–>子级中使用 @sestion(‘title’,’this is a title’);
1.3 继承 父级 内容,
父级:
@section(‘main’)
这个是父级的内容
@show
子级:
@section(‘main’)
@@parent
这个是子集的内容
@endsection
解析后的结果就是:
这个是父级的内容
这个是子集的内容
第二:基本数据展示
2.1 变量
{{$title}}
2.2 函数
{{csrf_field()}}
2.3 原样输出
@{{$name}}其中@符号代表原样输出
2.4 默认值
{{$name or 'default'}}
2.5 未转义输出
{!!$name!!}
第三:流程控制【结构控制】
3.1 @if() @elseif() @else @endif
3.2 @unless @endunless
3.3 @for() @endfor @foreach() @endforeach @forelse() @endforelse @while() @endwhile
第四:引入视图
@include(‘shared.errors’)
第五:多视图赋值
@each(‘view.name’,$job,’job’,’view.empty’)
第六:依赖注入
@inject('metrics','App\Services\MetricsService') {{$metrics->monthlyRevenue()}}
第七:自定义模版【扩展blade】
通过在 AppServiceProvider 里面的 boot 函数进行定义如下:
Blade::directive( 'datatime',function($expression){ return "<?php echo with($expressiong)->format('m/d/y H:i');?>" } ); {{datetim()}}:
相关文章推荐
- [李景山php]每天laravel[033]-laravel 基础知识 --- 数据库
- [李景山php]每天laravel[028]-laravel 基础知识 --- 响应
- [李景山php]每天laravel[034]-laravel 基础知识 --- 数据迁移及填充
- [李景山php]每天laravel[025]-laravel 基础知识 --- 控制器
- [李景山php]每天laravel[031]-laravel 基础知识 --- 服务容器
- [李景山php]每天laravel[024]-laravel 基础知识 --- 路由
- [李景山php]每天laravel[027]-laravel 基础知识 --- 请求
- [李景山php]每天laravel[035]-laravel 基础知识 --- Eloquent 模型之关系映射
- [李景山php]每天laravel[032]-laravel 基础知识 --- Contract 及 Facade
- [李景山php]每天laravel[029]-laravel 基础知识 --- 视图
- [李景山php]每天laravel[025]-laravel 基础知识 --- 中间件
- [李景山php]每天laravel[023]-laravel 中级任务--小白教程----实际操作-创建基础任务 to-do-list 案例 ---删除数据
- [李景山php]每天laravel[019]-laravel 中级任务--小白教程----实际操作-创建基础任务 to-do-list 案例 ---路由
- [李景山php]每天laravel-20161029|BladeCompiler-1.php
- [李景山php]每天laravel-20161030|BladeCompiler-2.php
- [李景山php]每天laravel[020]-laravel 中级任务--小白教程----实际操作-创建基础任务 to-do-list 案例 ---视图
- [李景山php]每天laravel[012]-laravel 中级任务翻译---创建 模版 及 视图
- [李景山php]每天laravel[023]-laravel 中级任务--小白教程----实际操作-创建基础任务 to-do-list 案例 ---主页,亲爱的,我回来了!!
- [李景山php]每天laravel[017]-laravel 中级任务--小白教程----实际操作-创建基础任务 to-do-list 案例 ---准备数据库
- [李景山php]每天laravel[023]-laravel 中级任务--小白教程----实际操作-创建基础任务 to-do-list 案例 ---登录,该死的登录