BladeOne
The standalone version Blade Template Engine without Laravel in a single php file and without dependencies
Install / Use
/learn @EFTEC/BladeOneREADME

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.
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 | |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------| | <img src="https://camo.githubusercontent.com/54b430c7161516534d99229cfcae75cf6b423c9a746aac42acb52ad5f0c5b8bb/68747470733a2f2f74686570726163746963616c6465762e73332e616d617a6f6e6177732e636f6d2f692f3436696b7061376661717677726533797537706a2e6a7067" alt="example php bladeone" width="200"/> | <img src="https://github.com/EFTEC/example.cupcakes/raw/master/docs/result.jpg" alt="example php bladeone cupcakes" width="200"/> | <img src="https://github.com/EFTEC/example-search/raw/master/img/search_bootstrap.jpg" alt="example php bladeone search" width="200"/> | <img src="https://github.com/EFTEC/example-php-editablegrid/raw/master/docs/final.jpg" alt="example php bladeone search" width="200"/> | | Custom control #1 | Custom control #2 | | | https://www.southprojects.com
Manual
- BladeOne Manual
- Template tags (views)
- 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
//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:
// 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)
$name=@$_GET['name'];
echo "my name is ".$name;
It could be separates as two files:
$name=@$_GET['name'];
include "template.php";
