PHP code example of jbzoo / less

1. Go to this page and download the library: Download jbzoo/less 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/ */

    

jbzoo / less example snippets


use JBZoo\Less\Less;

// Basic usage
$less = new Less();
$cssPath = $less->compile('/path/to/styles.less');

// With custom cache directory
$less = new Less(['cache_path' => './custom-cache']);
$cssPath = $less->compile('./assets/styles.less');

use JBZoo\Less\Less;

try {
    $less = new Less([
        // Compilation behavior
        'force'        => false,                    // Force recompilation on each call
        'debug'        => false,                    // Enable source maps (future feature)

        // Path configuration
        'root_url'     => 'http://site.com/',       // Root URL for CSS asset references
        'root_path'    => '/full/path/to/site',     // Full path to web root directory

        // LESS features
        'global_vars'  => [                         // Global variables available in all files
            'primary-color' => '#007bff',           // Becomes @primary-color: #007bff;
            'font-size'     => '14px',              // Becomes @font-size: 14px;
        ],

        'autoload'     => [                         // Files automatically ath(
        '/additional/import/directory/',
        'http://site.com/additional/directory/'     // URL mapping (optional)
    );

    // Compile LESS files
    $cssPath1 = $less->compile('/full/path/to/styles.less');
    $cssPath2 = $less->compile('./relative/path/to/styles.less');
    $cssPath3 = $less->compile(
        './relative/path/to/styles.less',
        'http://site.com/custom/base/path/'         // Override base path for URLs
    );

} catch (JBZoo\Less\Exception $e) {
    echo 'Compilation error: ' . $e->getMessage();
}