PHP code example of xinix-technology / bono-blade

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

    

xinix-technology / bono-blade example snippets


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

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

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

'bono.providers' => array(
    '\\Xinix\\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' => 'Xinix Technology'));
});

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' => 'Xinix Technology'));
});

@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' }}}