Download the PHP package nicksdot/blade-html-attributes without Composer
On this page you can find all versions of the php package nicksdot/blade-html-attributes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nicksdot/blade-html-attributes
More information about nicksdot/blade-html-attributes
Files in nicksdot/blade-html-attributes
Package blade-html-attributes
Short Description Laravel Blade directives for conditionally rendering HTML attributes
License MIT
Informations about the package blade-html-attributes
Blade HTML Attributes
A Laravel package that provides Blade directives for conditionally rendering HTML attributes.
Installation
The package will auto-register the service provider.
Available Directives
Behaviour Matrix
Note: Rows in bold show special operator = & ! behaviour.
| Value | @attr |
@data |
@aria |
@flag |
|---|---|---|---|---|
('foo', "bar") |
foo="bar" |
data-foo="bar" |
aria-foo="bar" |
foo |
('foo', "1") |
foo="1" |
data-foo="1" |
aria-foo="1" |
foo |
('foo', 1) |
foo="1" |
data-foo="1" |
aria-foo="1" |
foo |
('foo', true) |
foo |
data-foo |
aria-foo="true" |
foo |
('foo=', true) |
foo="true" |
data-foo="true" |
aria-foo="true" |
foo |
('foo', false) |
(nothing) | (nothing) | aria-foo="false" |
(nothing) |
('foo=', false) |
foo="false" |
data-foo="false" |
aria-foo="false" |
(nothing) |
('!foo', false) |
(throws) | (throws) | (nothing) | (throws) |
('foo', "0") |
foo="0" |
data-foo="0" |
aria-foo="0" |
(nothing) |
('foo', 0) |
foo="0" |
data-foo="0" |
aria-foo="0" |
(nothing) |
('foo', '') |
(nothing) | (nothing) | (nothing) | (nothing) |
('foo=', '') |
foo="" |
data-foo="" |
(nothing) | (nothing) |
('foo', ' ') |
(nothing) | (nothing) | (nothing) | (nothing) |
('foo=', ' ') |
foo=" " |
data-foo=" " |
(nothing) | (nothing) |
('foo', null) |
(nothing) | (nothing) | (nothing) | (nothing) |
Gotchas:
@attrand@dataallow the=suffix (e.g.,@attr('foo=', $value)) to force values (always render with="value", even for booleans and empty strings)@ariaallows the!prefix (e.g.,@aria('!foo', $value)) to negate false values for removing attribute entirely.
Descriptions
-
@attr: By default,truerenders as a boolean flag (attribute name only), andfalse/empty/whitespace-only/null render nothing. With the force-value operator (=suffix like'foo='), always renders with values including"true","false", and empty strings. -
@data: Same as@attrbut automatically prefixes attribute names withdata-. -
@aria: By default, renders all values including"true"and"false"(never as boolean flags). Never renders empty or whitespace-only strings. With the negation operator (!prefix like'! foo'),falsethe attribute is completely removed instead of rendering as"false". @flag: Outputs just the attribute name without a value (boolean flag), for truthy values only. Follows HTML spec for boolean attributes likedisabled,checked,requiredordata-foo.
Examples
@attr Directive
@data Directive
@aria Directive
@flag Directive
Requirements
- PHP 8.1+
- Laravel 10.0+
License
This package is open-sourced software licensed under the MIT licence.
Credits
All versions of blade-html-attributes with dependencies
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/view Version ^10.0|^11.0|^12.0|^13.0