Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
B

BladeOne

> 后端框架
Open source

The standalone version Blade Template Engine without Laravel in a single php file and without dependencies

830 stars0 likes3 views
WebsiteGitHub

About

The standalone version Blade Template Engine without Laravel in a single php file and without dependencies

BladeOne Blade Template Engine

BladeOne is a standalone version of Blade Template Engine that uses a single PHP file and can be ported and used in different projects. It allows you to use blade template outside Laravel.

Dynamic blade components are not supported (reason: performance purpose) and custom features aimed for blade, but everything else is supported.

Comparison with Twig

(spoiler) Twig is slower.

First Time Time First Time Memory Overload First Time Second Time Second Time Memory
BladeOne 1962ms 2024kb 263 1917ms 2024kb
Twig 3734ms 2564kb 123 3604ms 2327kb

What it was tested?. It was tested two features (that are the most used): It was tested with an array with 1000 elements and tested many times.

Comparison with Twig

NOTE about questions, reports, doubts or suggesting:

✔ If you want to open an inquiry, do you have a doubt, or you find a bug, then you could open an ISSUE.
Please, don't email me (or send me PM) directly for question or reports.
Also, if you want to reopen a report, then you are open to do that.
I will try to answer all and every one of the question (in my limited time).

Some example

ExampleTicketPHP Example cupcakes Example Search Example Editable Grid
Custom control #1 Custom control #2
https://www.southprojects.com

Manual

  • BladeOne Manual
  • Template tags (views)
    • Template variables
    • Template inheritance
    • Template component
    • Template stack
    • Template asset, relative, base, current and canonical links
    • Template calling methods
    • Template logic
    • Template loop
    • Template Pipes (Filter)
  • Custom Control
  • Methods of the class
  • Injecting logic before the view (composer)
  • Extending the class
  • Using BladeOne with YAF Yet Another Framework
  • Differences between Blade and BladeOne
  • Comparision with Twig (May-2020)
  • Changelog
  • Changes between 2.x and 3.0 and TODO
  • Code Protection (Sourceguardian and similars)

PHP 5.x support?

This version does not support PHP 5.x anymore. However, you can use the old version that is 100% functional with PHP 5.6 and higher.

Laravel blade tutorial

You can find some tutorials and example on the folder Examples.

You could also check the Wiki

About this version

By standard, The original Blade library is part of Laravel (Illuminate components) and to use this template library, you require install Laravel and Illuminate-view components. The syntax of Blade is pretty nice and bright. It's based in C# Razor (another template library for C#). It's starting to be considered a de-facto standard template system for many PHP (Smarty has been riding off the sunset since years ago) so, if we can use it without Laravel then it's a big plus for many projects. In fact, in theory, it is even possible to use with Laravel. Exists different versions of Blade Template that runs without Laravel, but most requires 50 or more files, and those templates add a new level of complexity, so they are not removing Laravel but hiding:

  • More files to manage.
  • Changes to the current project (if you want to integrate the template into an existent one)
  • Incompatibilities amongst other projects.
  • Slowness (if your server is not using op-cache)
  • Most of the code in the original Blade is used for future use, including the chance to use a different template engine.
  • Some Laravel legacy code.

This project uses a single file called BladeOne.php and a single class (called BladeOne). If you want to use it then include it, creates the folders and that's it!. Nothing more (not even namespaces)*[]: It is also possible to use Blade even with Laravel or any other framework. After all, BladeOne is native, so it's possible to integrate into almost any project.

Why to use it instead of native PHP?

Separation of concerns

Let’s say that we have the next code

php
//some PHP code
// some HTML code
// more PHP code
// more HTML code.

It leads to a mess of a code. For example, let’s say that we oversee changing the visual layout of the page. In this case, we should change all the code, and we could even break part of the programming.
Instead, using a template system works in the next way:

php
// some php code
ShowTemplate();

We are separating the visual layer from the code layer. As a plus, we could assign a non-php-programmer in charge to edit the template, and he/she doesn’t need to touch or know our php code.

Security

Let’s say that we have the next exercise (it’s a dummy example)

php
$name=@$_GET['name'];
echo "my name is ".$name;

It could be separates as two files:

php
$name=@$_GET['name'];
include "template.php";
php
// template.php
echo "my name is ".$name;

Even for this simple example, there is a risk of hacking. How? A user could send malicious code by using the GET variable, such as html or even javascript. The second file should be written as follows:

php
 // template.php
echo "my name is ".html_entities($name);

html_entities should be used in every single part of the visual layer (html) where the user could inject malicious code, and it’s a real tedious work. BladeOne does it automatically.

php
// template.blade.php
My name is {{$name}}

Easy to use

BladeOne is focused on an easy syntax that it's fast to learn and to write, while it could keep the power of PHP.

Let's consider the next template:

php

    
        value); ?> > text); ?>
    

With BladeOne, we could do the same with

php

    @foreach($countries as $c)
        value}} >{{echo html_entities($c->text)}}
    @nextforeach

And if we use thehtml extension we could even reduce to

php
@select('id1')
    @items($countries,'value','text','','')
@endselect()

Performance

This library works in two stages.

The first is when the template calls the first time. In this case, the template compiles and store in a folder.
The second time the template calls then, it uses the compiled file. The compiled file consist mainly in native PHP, so the performance is equals than native code. since the compiled version IS PHP.

Scalable

You could add and use your own function by adding a new method (or extending) to the BladeOne class. NOTE: The function should start with the name "compile"

php
protected function compileMyFunction($expression)
{
    return $this->phpTag . "echo 'YAY MY FUNCTION IS WORKING'; ?>";
}

Where the function could be used in a template as follows

php
@myFunction('param','param2'...)

Alternatively, BladeOne allows running arbitrary code from any class or method if its defined.

php
{{SomeClass::SomeMethod('param','param2'...)}}

Install (pick one of the next one)

  1. Download the file manually then unzip (using WinRAR,7zip or any other program) https://github.com/EFTEC/BladeOne/archive/master.zip
  2. git clone https://github.com/EFTEC/BladeOne (it doesn't include the examples)
  3. Composer. See usage
  4. wget https://github.com/EFTEC/BladeOne/archive/master.zip unzip master.zip

Usage

If you use composer, then you could add the library using the next command (command line)

bash
composer require eftec/bladeone

If you don't use it, then you could download the library and include it manually.

Explicit definition

php
use eftec\bladeone\BladeOne;

$views = __DIR__ . '/views';
$cache = __DIR__ . '/cache';
$blade = new BladeOne($views,$cache,BladeOne::MODE_DEBUG); // MODE_DEBUG allows to pinpoint troubles.
echo $blade->run("hello",array("variable1"=>"value1")); // it calls /views/hello.blade.php

Where $views is the folder where the views (templates not compiled) will be stored. $cache is the folder where the compiled files will be stored.

In this example, the BladeOne opens the template hello. So in the views-folder it should exist a file called hello.blade.php

views/hello.blade.php:

xml

Title

{{$variable1}}

Implicit defi

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPblade-templatelaravelloopphp

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架