PHPackages                             krisanalfa/bono-blade - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. krisanalfa/bono-blade

ActiveLibrary[Templating &amp; Views](/categories/templating)

krisanalfa/bono-blade
=====================

Laravel Blade template engine for Bono PHP Framework

1.0.0(10y ago)038011MITPHP

Since Mar 6Pushed 10y agoCompare

[ Source](https://github.com/krisanalfa/bono-blade)[ Packagist](https://packagist.org/packages/krisanalfa/bono-blade)[ RSS](/packages/krisanalfa-bono-blade/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (37)Used By (1)

BonoBlade
=========

[](#bonoblade)

Laravel Blade Template Engine for Bono PHP Framework

> **Note:** BonoBlade also use Blade templating for `partial` view

Installation
------------

[](#installation)

Add this line to your `composer.json` file

```
"require": {
    "krisanalfa/bono-blade": "~0.6.*"
},

```

Configuration
-------------

[](#configuration)

Add these lines to your configuration file

```
'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',
```

If you want to change layout file name, templates path, or cache path, you can add options in your provider like this

```
'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'
    ),
),
```

> **Note:** You may use any other theme based on `BladeTheme`, such as [blade foundation](https://github.com/krisanalfa/blade-foundation). Or you can create your own theme.

Basic usage
-----------

[](#basic-usage)

```
use Bono\App;

$app = App::getInstance();

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

Layout example
--------------

[](#layout-example)

```

    @yield('title', 'Devel')

        @yield('content')

```

Template example
----------------

[](#template-example)

```

@section('title')
New Title
@endsection

@section('content')
Hello, {{ $name }}!
@endsection
```

Rendering template
------------------

[](#rendering-template)

Simply, you can render your template by call `render` function in `\Bono\App` instance.

```
use Bono\App;

$app = App::getInstance();

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

> **Note:** Be sure you're not adding `.blade.php` or your template will not found

Result
------

[](#result)

```

    New Title

        Hello, Krisan Alfa Timur!

```

Rendering a page without layout
-------------------------------

[](#rendering-a-page-without-layout)

```
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'));
});
```

Working with sections
---------------------

[](#working-with-sections)

```

        @section('sidebar')
            This is the master sidebar.
        @show

            @yield('content')

```

```

@extends('myCustomLayout')

@section('sidebar')
    @parent

    This is appended to the master sidebar.
@stop

@section('content')
    This is my body content. Appended to the container.
@stop
```

Note that views which `extend` a Blade layout simply override sections from the layout. Content of the layout can be included in a child view using the `@parent` directive in a section, allowing you to append to the contents of a layout section such as a sidebar or footer.

Sometimes, such as when you are not sure if a section has been defined, you may wish to pass a default value to the `@yield` directive. You may pass the default value as the second argument:

```
@yield('content', 'Default')
```

Including sub-views
-------------------

[](#including-sub-views)

```
@include('view.name')
```

You may also pass an array of data to the included view:

```
@include('view.name', array('some'=>'data'))
```

Overwriting sections
--------------------

[](#overwriting-sections)

By default, sections are appended to any previous content that exists in the section. To overwrite a section entirely, you may use the `overwrite` statement:

```
@section('test')
   one
@stop
@section('test')
   two
@stop
@yield('test')
```

The outpur is:

```
one
```

But if you change the second `@stop` to an `@overwrite`.

```
@section('test')
   one
@stop
@section('test')
   two
@overwrite
@yield('test')
```

Then the following is output.

```
two
```

- `@overwrite` - End a Section and Overwrite it.
- `@stop` - Stopping Injecting Content Into a Section.
- `@show` - Yielding the Current Section in a Blade Template.
- `@append` - Stopping Injecting Content into a Section and Appending It.

Extends template to be reuseable
--------------------------------

[](#extends-template-to-be-reuseable)

```

@section('header')
My sexy header
@endsection

    @section('body')
        {{-- some other controll structure to make your page happens --}}
    @endsection

    @section('action')

            Edit
            Update

    @endsection

@section('footer')
My shiny footer
@endsection
```

```

@extends('listTemplate')

@section('body')
    {{-- some other controll structure to make your page happens --}}
    {{-- some kind that make this page unique --}}

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum eligendi, totam velit earum assumenda optio accusantium magni est maiores ad inventore expedita nisi minus autem, porro adipisci cupiditate in iure!

        Some bluish content

@overwrite
```

Based on this case, your `body` section will be overriden by `lorem ipsum` and `bluish content`.

Other blade control structures
------------------------------

[](#other-blade-control-structures)

### Echoing data

[](#echoing-data)

```
Hello, {{{ $name }}}.

The current UNIX timestamp is {{{ time() }}}.
```

### Echoing data after checking for existence

[](#echoing-data-after-checking-for-existence)

Sometimes you may wish to echo a variable, but you aren't sure if the variable has been set. Basically, you want to do this:

```
{{{ isset($name) ? $name : 'Default' }}}
```

However, instead of writing a ternary statement, Blade allows you to use the following convenient short-cut:

```
{{{ $name or 'Default' }}}
```

### Displaying raw text with curly braces

[](#displaying-raw-text-with-curly-braces)

If you need to display a string that is wrapped in curly braces, you may escape the Blade behavior by prefixing your text with an `@` symbol:

```
@{{ This will not be processed by Blade }}
```

Of course, all user supplied data should be escaped or purified. To escape the output, you may use the triple curly brace syntax:

```
Hello, {{{ $name }}}.
```

If you don't want the data to be escaped, you may use double curly-braces:

```
Hello, {{ $name }}.
```

> **Note:** Be very careful when echoing content that is supplied by users of your application. Always use the triple curly brace syntax to escape any HTML entities in the content.

### If statements

[](#if-statements)

```
@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
```

> **Note:** Method `@unless` is used when you want to write `@if(! functionReturnBool())`

### Loops

[](#loops)

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

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

@while (true)
    I'm looping forever.
@endwhile
```

### Comments

[](#comments)

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

\##Extending blade

```
use Bono\App;

$app = App::getInstance();

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

    return preg_replace($pattern, '$1', $view);
});
```

Now you can use `@dateTime($dateValue)` to get your datetime value.

The `createPlainMatcher` method is used for directives with no arguments like `@endif` and `@stop`, while `createMatcher` is used for directives with arguments.

```
use Bono\App;

$app = App::getInstance();

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

    return preg_replace($pattern, '', $view);
});

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

    return preg_replace($pattern, '', $view);
});
```

Now you can use `@pre` and `@endpre` whenever you want to `print_r()` your value. Just like this:

```
@pre
print_r($myPrettyPrintVariable)
@endpre
```

Setting the content tags blade uses
-----------------------------------

[](#setting-the-content-tags-blade-uses)

You know that blade uses `{{` and `}}` to specify content to be output, but this conflicts with Mustache or some other library you're using. If you want to use other tags, you can use `setContentTags` method. Let's say you want to use `[%` and `%]` for your tags.

```
use Bono\App;

$app = App::getInstance();

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

Then your template can contain code like.

```
The value of $variable is [% $variable %].
```

You can also pass a third argument as `true` to indicate you're setting the tags to **escape** content.

```
use Bono\App;

$app = App::getInstance();

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

Then instad of using `{{{` and `}}}` you can use `[-%` and `%-]`.

```
The HTML tags inside this value would be escaped [%- $variable -%].
```

> **Note:** You must call `setContentTags` method before using view. The best options is: make a `Provider` that preparing all of your Blade customization.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 93.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~15 days

Recently: every ~82 days

Total

36

Last Release

3912d ago

Major Versions

0.8.3 → 1.0.02015-08-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/5585ab7e83e92b16ebfde64d7d90ff330721bcb1fbfa193fb0ffe149a4b3a7d1?d=identicon)[krisanalfa](/maintainers/krisanalfa)

---

Top Contributors

[![krisanalfa](https://avatars.githubusercontent.com/u/3734729?v=4)](https://github.com/krisanalfa "krisanalfa (46 commits)")[![reekoheek](https://avatars.githubusercontent.com/u/299394?v=4)](https://github.com/reekoheek "reekoheek (3 commits)")

### Embed Badge

![Health badge](/badges/krisanalfa-bono-blade/health.svg)

```
[![Health](https://phpackages.com/badges/krisanalfa-bono-blade/health.svg)](https://phpackages.com/packages/krisanalfa-bono-blade)
```

###  Alternatives

[blade-ui-kit/blade-icons

A package to easily make use of icons in your Laravel Blade views.

2.5k34.2M309](/packages/blade-ui-kit-blade-icons)[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[moonshine/moonshine

Laravel administration panel

1.3k217.1k59](/packages/moonshine-moonshine)[livewire/blaze

A tool for optimizing Blade component performance by folding them into parent templates

688221.3k17](/packages/livewire-blaze)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
