php – Laravel 5.4刀片新组件的默认值?
发布时间:2020-12-14 19:41:41 所属栏目:大数据 来源:网络整理
导读:Laravel 5.4允许使用以下结构的组件: div class="alert alert-{{ $type }}" div class="alert-title"{{ $title }}/div {{ $slot }}/div 这被称为: @component('alert',['type' = 'danger']) @slot('title') oh no @endslot Foo@endcomponent 是否有速记或
Laravel 5.4允许使用以下结构的组件:
<div class="alert alert-{{ $type }}"> <div class="alert-title">{{ $title }}</div> {{ $slot }} </div> 这被称为: @component('alert',['type' => 'danger']) @slot('title') oh no @endslot Foo @endcomponent 是否有速记或刀片标记来设置传入的变量的默认值? 例如,在上面,如果我没有传入“类型”,我得到一个未定义的变量错误.我可以这样做: <div class="alert alert-{{ isset($type) ? $type : 'default' }}"> 但上述情况很冗长,特别是如果变量用于多个点.
我不这么认为.
说过刀片具有包装isset()调用的or运算符(see docs). <div class="alert alert-{{ $type or 'default' }}"> 如果你正在运行php 7,这就是Null coalescing operator的情况. <div class="alert alert-{{ $type ?? 'default' }}"> 两者都会使你的呼叫网站tider. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |