Easily handle conditional HTML generation with the following helpers.
Found this package helpful? Please consider supporting my work!
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 |
- Install the package with composer:
composer require okipa/laravel-html-helper
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.
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.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.