W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
Hello, {{ $name }}.
The current UNIX timestamp is {{ time() }}.
有時(shí)候您想要打印一個(gè)變量,但您不確定這個(gè)變量是否存在,通常情況下,您會(huì)想要這樣寫::
{{ isset($name) ? $name : 'Default' }}
然而,除了寫這種三元運(yùn)算符語(yǔ)法之外,Blade 讓您可以使用下面這種更簡(jiǎn)便的語(yǔ)法:
{{ $name or 'Default' }}
如果您需要顯示的一個(gè)字符串剛好被花括號(hào)包起來(lái),您可以在花括號(hào)之前加上 @ 符號(hào)
前綴來(lái)跳出 Blade 引擎的解析:
@{{ This will not be processed by Blade }}
如果您不想數(shù)據(jù)被轉(zhuǎn)義, 也可以使用如下語(yǔ)法:
Hello, {!! $name !!}.
特別注意: 在您的應(yīng)用程序打印用戶所提供的內(nèi)容時(shí)要非常小心。請(qǐng)記得永遠(yuǎn)使用雙重花括號(hào)來(lái)轉(zhuǎn)義內(nèi)容中的 HTML 實(shí)體字符串。
@if (count($records) === 1)
I have one record!
@elseif (count($records) > 1)
I have multiple records!
@else
I don't have any records!
@endif
@unless (Auth::check())
You are not signed in.
@endunless
@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
@include('view.name')
您也可以通過(guò)傳入數(shù)組的形式將數(shù)據(jù)傳遞給加載的子視圖:
@include('view.name', ['some' => 'data'])
如果想要重寫掉前面區(qū)塊中的內(nèi)容,您可以使用 overwrite 聲明:
@extends('list.item.container')
@section('list.item.content')
<p>This is an item of type {{ $item->type }}</p>
@overwrite
@lang('language.line')
@choice('language.line', 1)
{{-- This comment will not be in the rendered HTML --}}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: