pskordilakis/blade-class-directive

Laravel blade class directive
1,158 4
Install
composer require pskordilakis/blade-class-directive
Latest Version:v1.0.1
PHP:>=7.2
License:MIT
Last Updated:Jan 8, 2025
Links: GitHub  ·  Packagist
Maintainer: pskordilakis

Blade Class Directive

Inspired by classnames for react.

Installation

composer require pskordilakis/blade-class-directive

Usage

@class directive accepts a variable number of arguments that can be of type string or array and returns(prints) a class attribute for an HTML element. Any string argument will be added as part of the value of the class attribute. For the array arguments, the entries will be filtered based on the value (truthy/falsy) and the key will be added to the class value

String arguments

@class('btn btn-primary')

Array Arguments

@class([ 'btn' => true, 'btn-primary' => true, 'disabled' => $isDisabled ])

Mixed Arguments

@class('btn btn-primary', [ 'disabled' => $isDisabled ])

On HTML elements

<li @class('page-item', [ 'disabled' => $pagination->onFirstPage() ])></li>

Related Packages

bryanjhv/laravel-blade-cdn

Blade directive to get asset URLs according to environment.

178 2
spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

978,664 619
balping/laravel-blade-function

This Laravel 5.1+ package lets you declare functions inside blade templates.

10,602 21
devmcc/blade-extended

Expands the blade functionality of the Laravel framework with additional directi...

19 0
mindtwo/laravel-blade-spaceless

Blade @spaceless directive that strips whitespace between HTML tags at render ti...

37,660 2

Version History

Version Released PHP Laravel License
v1.0.1 >=7.2 ^5.8 MIT
v1.0.0 >=7.2 ^5.8 MIT