PHP code example of hirasso / attr

1. Go to this page and download the library: Download hirasso/attr library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hirasso / attr example snippets


 /** Example: render a button with custom classes and styles */  

 /** Example: render an x-data attribute for Alpine.js */  

// Fluent API
->class('block p-3')
->class('bg-blue-600 text-white', $isActive)

// Array class syntax (plain string)
'class' => 'block p-3'

// Array class syntax (conditional)
'class' => [
    'block p-3',
    'bg-blue-600 text-white' => $isActive,
]

// Anywhere else, use the /*tw*/ hint comment
$class = /*tw*/ 'text-white bg-blue-600';


<button <?= attr()
    ->set('type', 'button')
    ->set('disabled', $isDisabled)
    ->class('border p-3')
    ->class('bg-blue-600 text-white', $isActive)
    ->class('bg-white text-black', !$isActive)
    ->style('--highlight', 'red')
    ->style('display', 'none', $isHidden)
    ->aria('expanded', 'false')