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
复制代码

 

posted @   carol2014  阅读(6)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示