okipa / laravel-html-helper
Useful helpers to dynamically generate clean HTML with Laravel.
Fund package maintenance!
Ko Fi
paypal.me/arthurlorent
Installs: 51 751
Dependents: 4
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.4||^8.0
- illuminate/support: ^7.0||^8.0
Requires (Dev)
- nunomaduro/larastan: ^0.6
- orchestra/testbench: ^5.0||^6.0
- phpmd/phpmd: ^2.8
- squizlabs/php_codesniffer: ^3.5
README
⚠️ This package has been abandonned ⚠️
Easily handle conditional HTML generation with the following helpers.
Found this package helpful? Please consider supporting my work!
Compatibility
Laravel | PHP | Package |
---|---|---|
^7.* | ^7.4 | ^2.0 |
^5.8 | ^7.2 | ^1.3 |
^5.5 | ^7.2 | ^1.2 |
^5.5 | ^7.1 | ^1.0 |
Upgrade guide
Table of Contents
Installation
- Install the package with composer:
composer require okipa/laravel-html-helper
API
html_classes
Calling this helper generates an HTML class
tag encapsulating the given dynamic classes.
It accepts combination of strings, integers, arrays or null arguments.
@php $id = 17; $fullScreen = false; $darkMode = true; @endphp <div{{ html_classes( ['card', $id, 'text-left'], $fullScreen ? 'full-screen' : null, $darkMode ? ['bg-dark', 'text-white'] : null ) }}></div>
<div class="card 17 text-left bg-dark text-white"></div>
You can call app(Okipa\LaravelHtmlHelper\HtmlClasses)->toHtml($classes)
if you want to avoid helper use.
html_attributes
Calling this helper generates dynamic HTML attributes, taking care about the given key-only, value-only or key-value combinations.
It accepts combination of strings, arrays or null arguments.
@php $dragAndDrop = true; $disabled = false; @endphp <div{{ html_attributes( ['data-confirm' => __('Are you sure you want to delete this line?')], $dragAndDrop ? 'data-drag-drop' : null, $disabled ? ['disabled', 'data-forbid-click'] : null, 'required' ) }}></div>
<div data-confirm="Are you sure you want to delete this line?" data-drag-drop required></div>
You can call app(Okipa\LaravelHtmlHelper\HtmlAttributes)->toHtml($attributes)
if you want to avoid helper use.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.