Laravel中的模板引擎Blade
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | <! DOCTYPE html> < html lang="en"> < head > < meta charset="UTF-8"> < title >模板继承@yield('title')</ title > < style > .header{ width: 1000px; height:150px; margin: 0 auto; background: #f5f5f5; border: 1px solid #dddddd; } .main{ width: 1000px; height:300px; margin: 0 auto; margin-top: 15px; clear:both; } .main .sidebar{ float:left; width:20%; height:inherit; background: #f5f5f5; border:1px solid #ddd; } .main .content{ float: right; width: 75%; height: inherit; background: #f5f5f5; border:1px solid #ddd; } .footer{ width:1000px; height:150px; margin: 0 auto; margin-top:15px; background: #f5f5f5; border:1px solid #ddd; } </ style > </ head > < body > < div class="header"> @section('header') 头部 @show </ div > < div class="main"> < div class="sidebar"> <!--section是用来定义一个视图片段的--> @section('sidebar') 侧边栏 @show </ div > < div class="content"> <!--yield表示某个指定section所要显示的内容,可以想象成一个占位符--> @yield('content','主要内容区域') </ div > </ div > < div class="footer"> @section('footer') 底部 @show </ div > </ body > </ html > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | @extends('layouts') @section('header') @parent header @stop @section('sidebar') sidebar @stop @section('content') content <!--模板中输出PHP变量--> < p >{{$name}}</ p > <!--模板中调用php代码--> < p >{{time()}}</ p > < p >{{date('Y-m-d H:i:s',time())}}</ p > < p >{{in_array($name,$arr)?'true':'false'}}</ p > < p >{{var_dump($arr)}}</ p > < p >{{isset($name)?$name:'default'}}</ p > < p >{{$name or 'default'}}</ p > <!--原样输出--> < p >@{{ $name }}</ p > <!--模板中的注释--> <!--引入子视图include--> @include('user.common1',['message'=>'这里是错误信息']) <!--流程控制--> @if($name=='yxh') I'm yxh @elseif($name=='imooc') I'm imooc @else who am I? @endif @if(in_array($name,$arr)) true @else false @endif @unless($name!='yxh') I'm yxh; @endunless @for($i=0;$i< 3 ;$i++) {{$i}} @endfor {{--@foreach($user as $user)--}} {{--{{$user->username}}--}} {{--@endforeach--}} @forelse($user as $user) {{$user->username}} @empty null @endforelse < a href="{{url('url')}}">url()</ a > < a href="{{action('UserController@urlTest')}}">action()</ a > < a href="{{route('url')}}">route()</ a > @stop |
1 | < p >这里是include{{$message}}</ p > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public function section1(){ $name = 'yxh' ; $arr = [ 'yxh' , 'imooc' ]; $user = Admin::get(); return view( 'user.section1' ,[ 'name' => $name , 'arr' => $arr , 'user' => $user ]); } public function urlTest(){ return 'urlTest' ; } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战