PHP code example of krisanalfa / bono-blade

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

    

krisanalfa / bono-blade example snippets


'bono.providers' => array(
    '\\KrisanAlfa\\Blade\\Provider\\BladeProvider'
),

// Bono Themeing
'bono.theme' => array(
    'class' => '\\KrisanAlfa\\Theme\\BladeTheme', // You can use another theme that extends from bono
),

// Bono Partial (segment of template)
'bono.partial.view' => '\\KrisanAlfa\\Blade\\BonoBlade',

'bono.providers' => array(
    '\\KrisanAlfa\\Blade\\Provider\\BladeProvider' => array(
        'templates.path' => array('pathToTemplatesPath'), // Default is array('../templates')
        'cache.path' => 'pathToCachePath',                // Default is '../cache'
        'layout' => 'customLayoutName',                   // Default is 'layout'
    ),
),

use Bono\App;

$app = App::getInstance();

$app->get('/', function () use ($app) {
    $app->render('yourTemplateName', array('var' => 'value'));
});

use Bono\App;

$app = App::getInstance();

$app->get('/', function () use ($app) {
    $app->view->setLayout('myLayout');
    $app->render('myTemplate', array('name' => 'Krisan Alfa Timur'));
});

use Bono\App;

$app = App::getInstance();

$app->get('/', function () use ($app) {
    // This method is same with $app->theme->partial($templateName, $data)
    $app->view->display('myTemplateWithoutLayout', array('name' => 'Krisan Alfa Timur'));
});

@if (count($records) === 1)
    I have one record!
@elseif (count($records) > 1)
    I have multiple records!
@else
    I don't have any records!
@endif

@unless (App::getInstance()->auth->check())
    You are not signed in.
@endunless

@for ($i = 0; $i < 10; $i++)
    The current value is {{ $i }}
@endfor

@foreach ($users as $user)
    <p>This is user {{ $user->id }}</p>
@endforeach

@while (true)
    <p>I'm looping forever.</p>
@endwhile

{{-- This comment will not be in the rendered HTML --}}

use Bono\App;

$app = App::getInstance();

$app->view->extend(function($view, $compiler) {
    $pattern = $compiler->createMatcher('datetime');

    return preg_replace($pattern, '$1 echo $2->format("m/d/Y H:i:s"); 

use Bono\App;

$app = App::getInstance();

$app->view->extend(function($view, $compiler) {
    $pattern = $compiler->createPlainMatcher('pre');

    return preg_replace($pattern, '<pre>', $view);
});

$app->view->extend(function($view, $compiler) {
    $pattern = $compiler->createPlainMatcher('endpre');

    return preg_replace($pattern, '</pre>', $view);
});

use Bono\App;

$app = App::getInstance();

$app->view->setContentTags('[%', '%]');

use Bono\App;

$app = App::getInstance();

$app->view->setContentTags('[%', '%]', true);
html
{{{ isset($name) ? $name : 'Default' }}}