larvel blade模板
模板
//定义布局 <html> <head> <title>App Name - @yield('title')</title> </head> <body> @section('sidebar') This is the master sidebar. @show //@show 则在定义的同时 立即 yield 这个片段 <div class="container"> @yield('content') </div> </body> </html> //扩展布局 @extends('layouts.app') @section('title', 'Page Title') @section('sidebar') @parent //@parent 指令向布局的 sidebar 追加(而非覆盖)内容 <p>This is appended to the master sidebar.</p> @endsection //@endsection 指令仅定义了一个片段 @section('content') <p>This is my body content.</p> @endsection
显示数据
//将被 PHP 的 htmlspecialchars 函数自动转义以防范 XSS 攻击 {{ $name }} //展示非转义数据 {!! $name !!} //json数据 <script> var app = @json($array); </script>
Blade 指令
//php @php // @endphp // If 语句 @if (count($records) === 1) // 有一条记录 @elseif (count($records) > 1) // 有多条记录 @else // 没有记录 @endif //循环 @for ($i = 0; $i < 10; $i++) The current value is {{ $i }} @endfor @foreach ($users as $user) <p>This is user {{ $user->id }}</p> @endforeach @forelse ($users as $user) <li>{{ $user->name }}</li> @empty <p>No users</p> @endforelse @while (true) <p>I'm looping forever.</p> @endwhile @foreach ($users as $user) @if ($user->type == 1) @continue @endif <li>{{ $user->name }}</li> @if ($user->number == 5) @break @endif @endforeach @foreach ($users as $user) @if ($loop->first) This is the first iteration. @endif @if ($loop->last) This is the last iteration. @endif <p>This is user {{ $user->id }}</p> @endforeach
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix