PHP code example of berry / alpinejs

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

    

berry / alpinejs example snippets




use Berry\Element;

use function Berry\Html\button;
use function Berry\Html\div;
use function Berry\Html\span;

function renderCounter(): Element
{
    return div()
        ->xData(['count' => 0])
        ->children(
            button()->xOnClick('count++')->text('Increment'),
            span()->xText('count'),
        );
}



use Berry\Element;

use function Berry\Html\button;
use function Berry\Html\div;

function renderDropdown(): Element
{
    return div()
        ->xData(['open' => false])
        ->children(
            button()->xOnClick('open = ! open')->text('Toggle'),
            div()->xShow('open')->xOnClickOutside('open = false')->text('Contents...'),
        );
}