# BladeOne
**Repository Path**: statx/BladeOne
## Basic Information
- **Project Name**: BladeOne
- **Description**: https://github.com/EFTEC/BladeOne
- **Primary Language**: PHP
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2023-01-14
- **Last Updated**: 2025-11-17
## Categories & Tags
**Categories**: Uncategorized
**Tags**: template
## README

# 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.
[](https://packagist.org/packages/eftec/bladeone)
[](https://packagist.org/packages/eftec/bladeone)
[]()
[]()
[]()
[]()
[]()
[]()
> 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](https://github.com/EFTEC/BladeOne/wiki/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](https://github.com/EFTEC/BladeOne/issues).
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](https://github.com/jorgecc/ExampleTicketPHP) | [Example cupcakes](https://github.com/EFTEC/example.cupcakes) | [Example Search](https://github.com/EFTEC/example-search) | [Example Editable Grid](https://github.com/EFTEC/example-php-editablegrid) |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
| |
|
|
|
| [Custom control #1](https://github.com/EFTEC/BladeOne/blob/master/examples/example_customcontrol.php) | [Custom control #2](https://github.com/EFTEC/BladeOne/blob/master/examples/example_customcontrol2.php) | | |
[https://www.southprojects.com](https://www.southprojects.com)
## Manual
* [BladeOne Manual](https://github.com/EFTEC/BladeOne/wiki/BladeOne-Manual)
* [Template tags (views)](https://github.com/EFTEC/BladeOne/wiki/Template-tags)
* [Template variables](https://github.com/EFTEC/BladeOne/wiki/Template-variables)
* [Template inheritance](https://github.com/EFTEC/BladeOne/wiki/Template-inheritance)
* [Template component](https://github.com/EFTEC/BladeOne/wiki/Template-Component)
* [Template stack](https://github.com/EFTEC/BladeOne/wiki/Template-stack)
* [Template asset, relative, base, current and canonical links](https://github.com/EFTEC/BladeOne/wiki/Template-Asset,-Relative,-Base-and-Canonical-Links)
* [Template calling methods](https://github.com/EFTEC/BladeOne/wiki/Template-calling-methods)
* [Template logic](https://github.com/EFTEC/BladeOne/wiki/Template-logic)
* [Template loop](https://github.com/EFTEC/BladeOne/wiki/Template-loop)
* [Template Pipes (Filter)](https://github.com/EFTEC/BladeOne/wiki/Template-Pipes-(Filter))
* [Custom Control](https://github.com/EFTEC/BladeOne/wiki/Custom-Control)
* [Methods of the class](https://github.com/EFTEC/BladeOne/wiki/Methods-of-the-class)
* [Injecting logic before the view (composer)](https://github.com/EFTEC/BladeOne/wiki/Injecting-logic-before-the-view-(composer))
* [Extending the class](https://github.com/EFTEC/BladeOne/wiki/Extending-the-class)
* [Using BladeOne with YAF Yet Another Framework](https://github.com/EFTEC/BladeOne/wiki/Using--BladeOne-with-YAF)
* [Differences between Blade and BladeOne](https://github.com/EFTEC/BladeOne/wiki/Differences-between-Blade-and-BladeOne)
* [Comparision with Twig (May-2020)](https://github.com/EFTEC/BladeOne/wiki/Comparison-with-Twig)
* [Changelog](https://github.com/EFTEC/BladeOne/wiki/Changelog)
* [Changes between 2.x and 3.0 and TODO](https://github.com/EFTEC/BladeOne/wiki/Changes-between-2.x-and-3.0-and-TODO)
* [Code Protection (Sourceguardian and similars)](https://github.com/EFTEC/BladeOne/wiki/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](examples).
You could also check the [Wiki](https://github.com/EFTEC/BladeOne/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 // index.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 // template.php
```
With BladeOne, we could do the same with
```php // template.blade.php
```
And if we use thehtml extension we could even reduce to
```php // template.blade.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](#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)
```shell
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:
```html