PHP code example of alexoliverwd / brace

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

    

alexoliverwd / brace example snippets




use Brace\Parser;

$brace = new Parser();

// Register filters
$brace->registerFilter('int', fn($content) => (int) $content);
$brace->registerFilter('decimal', fn($number) => number_format($number, 2));
$brace->registerFilter('uppercase', fn($content) => strtoupper($content));
$brace->registerFilter('titlecase', fn($content) => ucwords($content));
$brace->registerFilter('striptags', fn($content) => strip_tags($content));

// Register shortcode
$brace->regShortcode('add_to_basket_button', fn($attrs) => sprintf(
    '<button id="%d">Add to basket</button>',
    $attrs['product_id'],
));

$brace->parse('template, document-footer', [
    'name' => 'Jane Doe',
    'products' => [
        0 => [
            'id' => 1154,
            'price' => 22.66,
            'title' => 'Product Number One',
            'description' => 'This is a product description',
        ],
        1 => [
            'id' => 1156,
            'price' => 16,
            'title' => 'Product Number Two',
            'description' => 'This is another product description',
        ],
    ],
]);