【发布时间】:2017-03-23 03:07:34
【问题描述】:
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
是否有简写或刀片标记来为传入的变量设置默认值?
例如,在上面,如果我没有传入“type”,我会得到一个undefined variable 错误。我可以这样做:
<div class="alert alert-{{ isset($type) ? $type : 'default' }}">
但是上面的内容感觉很冗长,特别是如果变量在多个地方使用。
【问题讨论】:
标签: php laravel laravel-5 laravel-5.4