kallbuloso/laravel-blade-directives

v1.0.4 2020-04-18 04:03 UTC

This package is auto-updated.

Last update: 2024-09-18 14:10:36 UTC


README

Latest Version on Packagist Total Downloads Software License Build Status

一组优秀的 Laravel Blade 指令。

安装

您可以通过 composer 安装此包

composer require kallbuloso/laravel-blade-directives

用法

@istrue

$variable 已设置且为真时显示。

@istrue($variable)
   This will be echoed
@endistrue

或者当您想快速输出时。

@istrue($variable, 'This will be echoed')

@isfalse

@istrue 相同,但检查 isset 和 false。

@isfalse($variable)
   This will be echoed
@endisfalse

@isnull

仅当 $variable 为 null 时显示。

@isnull($variable)
   This will be echoed
@endisnull

@isnotnull

@isnull 相同,但 $variable 不是 null 时显示。

@isnotnull($variable)
   This will be echoed
@endisnotnull

@dump 和 @dd

@dump($var)

@dd($var)

@mix

创建一个 HTML 元素来为 Laravel-Mix 的 css 或 js。

@mix('/css/app.css')
@mix('/js/app.js')

输出

<link rel="stylesheet" href="{{ mix('/css/app.css') }}">
<script src="{{ mix('/js/app.js') }}"></script>

@style

创建一个 <style> 元素或带有 css 路径的 <link> 元素。

@style
    body { background: black }
@endstyle


@style('/css/app.css')

@script

创建一个带有或不带有 js 路径的 <script> 元素。

@script
    alert('hello world')
@endscript


@script('/js/app.js')

@inline

在视图中内联加载 css 或 js 文件的 contents。

@inline('/js/manifest.js')

@pushonce

@push 相同,但只包含一次内容。对于可重复的块很有用。

第一个参数必须遵循语法 stack-name:group-name

@pushonce('js:foobar')
    <script src="{{ asset('/js/foobar.js') }}"></script>
@endpushonce

包含使用标准 @stack 指令的 pushes

@stack('js')

@routeis

检查当前路由名称是否等于给定参数。您可以使用通配符,如 blog.post.*

@routeis('webshop.checkout')
    Do something only on the checkout
@endrouteis

@routeisnot

检查当前路由名称是否不等于给定参数。您可以使用通配符,如 blog.post.*

@routeisnot('webshop.checkout')
    Do something only if this is not the checkout
@endrouteisnot

@instanceof

检查第一个参数是否是第二个参数的实例。

@instanceof($user, 'App\User')
    User is an instance of App\User
@endinstanceof

@typeof

检查参数是否为特定类型。

@typeof($text, 'string')
    Text is a string
@endtypeof

@repeat

重复指定次数的内容。

@repeat(3)
    Iteration #{{ $iteration }}
@endrepeat

@fa, @fas, @far, @fal, @fab, @mdi, @glyph

快速输出 Font Awesome、Material Design Icons 或 Glyphicon 图标。

@fa('address-book', 'optional-extra-class')

// for Font Awesome 5 (solid, regular, light, brand):
@fas('address-book', 'optional-extra-class')
@far('address-book', 'optional-extra-class')
@fal('address-book', 'optional-extra-class')
@fab('address-book', 'optional-extra-class')

// for Material Design Icons
@mdi('account', 'optional-extra-class')

// for Glyphicons
@glyph('glass', 'optional-extra-class')

@data

从数组中输出数据属性。

@data(['testing' => 123])

@haserror

快速输出,用于经典 $errors->has('input_name') 以确定是否存在给定字段的错误消息。

@haserror('input_name')
    This input has an error
@endhaserror

测试

composer test

贡献

欢迎贡献,感谢大家 的贡献 :)

关于 kallbuloso

kallbuloso 是来自荷兰的一个小型团队。我们为 web 开发创建(开源)工具,并在 Medium 上撰写相关主题。您可以在 Twitter 上关注我们,给我们买杯啤酒 或在 Patreon 上支持我们。

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件