An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
July 28, 2021 09:49 pm GMT
Original Link: https://dev.to/sureshramani/conditional-classes-blade-directives-in-laravel-3oa4
Conditional Classes Blade Directives in Laravel
New in Laravel 8.51: @class Blade directive to add true/false conditions on whether some CSS class should be added.
The @class directive conditionally compiles a CSS class string. The directive accepts an array of classes where the array key contains the class or classes you wish to add, while the value is a boolean expression. If the array element has a numeric key, it will always be included in the rendered class list:
@php $hasError = true;@endphp<span @class([ 'p-4', 'bg-red' => $hasError,])></span>
Thank you for reading this blog.
Original Link: https://dev.to/sureshramani/conditional-classes-blade-directives-in-laravel-3oa4
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To