Recommend this page to a friend! |
Classes of Jorge Castro | Gentelella BladeOne | vendor/eftec/bladeone/README.md | Download |
|
![]() BladeOne Blade Template EngineBladeOne 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. ????????-??? ????????? ?????? ???? Blade-????????, ??????? ?????????? ???? PHP-???? ? ????? ???? ??????????? ? ???????????? ? ????????? ????????. ?? ????????? ???????????? ?????? Blade ?? ????????? laravel. NOTE: So far it's apparently the only one project that it's updated with the latest version of Blade 7 (March 2020). It misses some commands missing but nothing more. ??????????: ?? ??? ??? ???, ??????, ?????? ???? ??????, ??????? ??????????? ? ????????? ??????? Blade 7 (2020 ?????). ?? ?????????? ????????? ??????? ???????????, ?? ?????? ??????. 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/3c938f71f46a90eb85bb104f0f396fcba62b8f4a/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"/> | Manual
Why does it support PHP 5.x?As for today (January 2021), PHP 5.x is still strong even when it is discontinued, but my main problem is the performance.
Laravel blade tutorialYou can find some tutorials and example on the folder Examples. You could also check the wiki Wiki About this versionBy 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 its 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:
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 concernsLet?s say that we have the next 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:
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. SecurityLet?s say that we have the next exercise (it?s a dummy example)
It could be separates as two files:
Even for this simple example, there is a risk of hacking. How? A user could sends malicious code by using the GET variable, such as html or even javascript. The second file should be written as follow:
html_entities should be used in every single part of the visual layer (html) where the user could injects malicious code, and it?s a real tedious work. BladeOne does it automatically.
Easy to useBladeOne 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:
With BladeOne, we could do the same with
And if we use thehtml extension we could even reduce to
PerformanceThis 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. ScalableYou 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"
Where the function could be used in a template as follow
Alternatively, BladeOne allows to run arbitrary code from any class or method if its defined.
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 3) Composer. See usage 4) wget https://github.com/EFTEC/BladeOne/archive/master.zip unzip master.zip UsageIf you use composer, then you could add the library using the next command (command line) > composer require eftec/bladeone If you don't use it, then you could download the library and include it manually. Implicit definition
Where 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:
ExplicitIn this mode, it uses the folders
Fluent
Filter (Pipes)It is possible to modify the result by adding filters to the result. Let's say we have the next value $name='Jack Sparrow'
Our view could look like:
What if we want to show the name in uppercase?. We could do in our code $name=strtoupper('Jack Sparrow'). With Pipes, we could do the same as follow:
We could also add arguments and chain methods.
You can find more information on https://github.com/EFTEC/BladeOne/wiki/Template-Pipes-(Filter) Security (optional)
If you log in using blade then you could use the tags @auth/@endauth/@guest/@endguest
or
Extensions Libraries (optional)https://github.com/eftec/BladeOneHtml Calling a static methods inside the template.Since 3.34, BladeOne allows to call a static method inside a class. Let's say we have a class with namespace \namespace1\namespace2
Method 1 PHP StyleWe could add a "use" in the template. Example: Add the next line to the template
and the next lines to the template (different methods)
> All those methods are executed at runtime Method 2 AliasOr we could define alias for each classes. php code:
Template:
> We won't need alias or use for global classes. Named argument (since 3.38)BladeOne allows named arguments. This feature must be implemented per function. Let's say the next problem: It is the old library BladeOneHtml:
And it is the next library:
The old method select only allows a limited number of arguments. And the order of the arguments is important. The new method select allows to add different types of arguments BladeOneHtmlIt is a new extension to BladeOne. It allows to create html components easily and with near-to-native performance. It uses a new feature of BladeOne: named arguments Example to create a select:
https://github.com/eftec/BladeOneHtml You could download it or add it via Composer > composer require eftec/bladeonehtml CollaborationYou are welcome to use it, share it, ask for changes and whatever you want to. Just keeps the copyright notice in the file. Future
LicenseMIT License. BladeOne (c) 2016-2021 Jorge Patricio Castro Castillo Blade (c) 2012 Laravel Team (This code is based and inspired in the work of the team of Laravel, however BladeOne is mostly a original work) |