Laravel中的模板引擎Blade
2024-09-06 23:24:46
<!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>
@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
<p>这里是include{{$message}}</p>
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';
}
最新文章
- 【原创】.NET平台机器学习组件-Infer.NET连载(一)介绍
- Python error: ascii’/&#39;utf-8′ codec can’t decode byte 0xb8 in position 50: ord
- 把Arraylist转换成GameObject[]
- await和async关键字来写异步程序
- Apple Watch开发之界面之间的正向传值
- 查看局域网内某个ip的mac地址
- Linux企业级项目实践之网络爬虫(9)——通过URL抓取网页内容
- 使用安卓中的TextToSpeech控件实现朗读文字
- JAVA GUI学习 - JSplitPane分屏组件学习
- jquery 如何动态添加、删除class样式方法介绍
- jsp中使用java函数
- sql查询调优之where条件排序字段以及limit使用索引的奥秘
- Solr管理界面详解
- collections deque队列及其他队列
- GNU C 与 ANSI C的区别
- MNIST机器学习入门
- JBoss/Wildfly 配置SQLserver服务器
- mongoDB进行分组操作
- git 先创建本地仓库,再关联远程
- Failed to place enough replicas
热门文章
- 求两个有序数组的中位数(4. Median of Two Sorted Arrays)
- 解决怎样监听Activity切换
- javaScript中innerHTML,innerText,outerHTML,outerText的区别
- 图像处理之opencv---加减乘除运算cvdiv
- 用 ERD 盘解决 Win8 自己主动更新后不能启动的问题
- 【转】IDA远程调试 The debugger could not attach to the selected process. irs_recv 等待的操作过时
- NS3网络仿真(11): ARP
- BestCoder #47 1001&;amp;&;amp;1002
- Darwin Streaming Server编译
- 索引大小 975.45 MB (1,022,836,736)