PHP Classes
elePHPant
Icontem

BladeOne: Standalone template engine that compiles into PHP

Recommend this page to a friend!
  Info   View files View files (113)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-11-02 (1 month ago) RSS 2.0 feedStarStarStarStar 78%Total: 316 This week: 2All time: 7,068 This week: 183Up
Version License PHP version Categories
bladeone 1.47MIT/X Consortium ...5.4PHP 5, Cache, Templates, Code Generation
Description Author

This package is a standalone template engine that compiles into PHP.

It is a version of the Blade template engine that uses as single PHP file and can be used with different frameworks or no framework at all.

It can compiles templates to a PHP file. Templates use the ASP.NET Razor and Moustache syntax.

Innovation Award
PHP Programming Innovation award nominee
July 2016
Number 5
ASP.NET Razor is a format for defining templates that are processed on the server side by .NET applications.

This package is template engine that compiles templates into PHP code from template files in either the ASP.NET Razor and Moustache syntax.

Manuel Lemos
  Performance   Level  
Name: Jorge Castro <contact>
Classes: 7 packages by
Country: Chile Chile
Age: 42
All time rank: 255110 in Chile Chile
Week rank: 12 Up1 in Chile Chile Up
Innovation award
Innovation award
Nominee: 4x

Winner: 1x

Details

Logo

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.

Бладеоне-это отдельная версия ядра Blade-шаблонов, которая использует один PHP-файл и может быть портирована и использована в различных проектах. Он позволяет использовать шаблон Blade за пределами laravel.

Build Status Packagist [Maintenance]() [composer]() [php]() [php]() [CocoaPods]()

NOTE: So far it's apparently the only one project that it's updated with the latest version of Blade 5.6 (September 2018). It misses some commands missing but nothing more.

Примечание: до сих пор это, видимо, только один проект, который обновляется с последней версией Blade 5,6 (Июль 2018). Он пропускает некоторые команды отсутствует, но ничего больше.

laravel blade tutorial

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

About this version

By standard, Blade is part of Laravel (Illuminate components) and for to use it, you require to install Laravel and Illuminate-view components. Blade as a template engine is pretty nice and clear. Also, it generates a (some that) clean code. And its starting to be considered a de-facto template system for PHP (Smarty has been riding off the sunset since years ago). So, if we are able to 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 version of Blade Template that runs without Laravel but most requires 50 or more files and those templates add a new level of complexity:

  • More files to manages.
  • 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)*[]:

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";
// template.php
echo "my name is ".$name;

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:

 // 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 injects malicious code, and it’s a real tedious work. BladeOne does it automatically.

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

Easy to use

BladeOne is focused on templates and the syntax of the code is aiming to be clean.

Let's consider the next template:

<select>
    <? foreach($countries as $c) { ?>
        <option value=<? echo html_entities($c->value); ?> > <? echo html_entities($c->text); ?></option>
    <? } ?>
</select>

With BladeOne, we could do the same with

<select>
    @foreach($countries as $c)
        <option value={{$c->value}} >{{echo html_entities($c->text)}}</option>
    @nextforeach
</select>

And with html extension we could even reduce to

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

Performance

This library works in two stages.

The first is when the template is called the first time. In this case, the template is compiled and stored in a folder. The second time the template is called 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 starts with the name "compile"

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

Where the function could be used in a template as follow

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

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

{{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 git clone https://github.com/EFTEC/BladeOne 3) Composer. See usage 4) wget https://github.com/EFTEC/BladeOne/archive/master.zip unzip master.zip

Usage

Without composer's autoload.php

example.php:

include "lib/BladeOne.php"; // you should change it and indicates the correct route.
Use eftec\bladeone;

$views = __DIR__ . '/views'; // it uses the folder /views to read the templates
$cache = __DIR__ . '/cache'; // it uses the folder /cache to compile the result. 
$blade=new bladeone\BladeOne($views,$cache,BladeOne::MODE_AUTO));
echo $blade->run("hello",array("variable1"=>"value1")); // /views/hello.blade.php must exist

Without namespace nor composer

include "../lib/BladeOne.php";

// The nulls indicates the default folders. By drfault it's /views and /compiles
// \eftec\bladeone\BladeOne::MODE_DEBUG is useful because it indicates the correct file if the template fails to load.  
//  You must disable it in production. 
$blade=new \eftec\bladeone\BladeOne(null,null,\eftec\bladeone\BladeOne::MODE_DEBUG);

echo $blade->run("Test.hello", []); // the template must be in /views/Test/hello.blade.php

Without composer's autoload.php_

require "vendor/autoload.php";

Use eftec\bladeone;

$views = __DIR__ . '/views';
$cache = __DIR__ . '/cache';
$blade=new bladeone\BladeOne($views,$cache,BladeOne::MODE_AUTO);
echo $blade->run("hello",array("variable1"=>"value1"));

Run the next composer command:

> composer require eftec/bladeone

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 folders it should exists a file called hello.blade.php

views/hello.blade.php:

<h1>Title</h1>
{{$variable1}}

Security (optional)

require "vendor/autoload.php";

Use eftec\bladeone;

$views = __DIR__ . '/views';
$cache = __DIR__ . '/cache';
$blade=new bladeone\BladeOne($views,$cache,BladeOne::MODE_AUTO);

$blade->login('johndoe','admin'); // where johndoe is an user and admin is the role. The role is optional

echo $blade->run("hello",array("variable1"=>"value1"));

If you login using blade then you could use the tags @auth/@endauth/@guest/@endguest

@auth
    // The user is authenticated...
@endauth

@guest
    // The user is not authenticated...
@endguest

or

@auth('admin')
    // The user is authenticated...
@endauth

@guest('admin')
    // The user is not authenticated...
@endguest

Business Logic/Controller methods

constructor

$blade=new bladeone\BladeOne($views,$cache,$mode);
  • BladeOne(templatefolder,compiledfolder,$mode) Creates the instance of BladeOne.
  • templatefolders indicates the folder (without ending backslash) of where the template files (*.blade.php) are located.
  • compiledfolder indicates the folder where the result of files will be saves. This folder should has write permission. Also, this folder could be located outside of the Web Root.
  • mode (optional). It sets the mode of the compile. See setMode(mode) . By default it's automatic

run

echo $blade->run("hello",array("variable1"=>"value1"));
  • run([template],[array]) Runs the template and generates a compiled version (if its required), then it shows the result.
  • template is the template to open. The dots are used for to separate folders. If the template is called "folder.example" then the engine tries to open the file "folder\example.blade.php"
  • array (optional). Indicates the values to use for the template. For example ['v1'=>10'], indicates the variable $v1 is equals to 10

setMode

It sets the mode of compilation.

> It the constant BLADEONE_MODE is define, then it has priority over setMode()

|mode|behaviour| |---|---| |BladeOne::MODE_AUTO|Automatic, BladeOne checks the compiled version, if it is obsolete, then a new version is compiled and it replaces the old one| |BladeOne::MODE_SLOW|Slow, BladeOne always compile and replace with a new version. It is useful for development| |BladeOne::MODE_FAST|Fast, Bladeone never compile or replace the compiled version, even if it doesn't exist| |BladeOne::MODE_DEBUG| It's similar to MODE_SLOW but also generates a compile file with the same name than the template.

setFileExtension($ext), getFileExtension

It sets or gets the extension of the template file. By default, it's .blade.php

> The extension includes the leading dot.

setCompiledExtension($ext), getCompiledExtension

It sets or gets the extension of the template file. By default, it's .bladec

> The extension includes the leading dot.

runString

echo $blade->runString('<p>{{$direccion}}</p>', array('direccion'=>'cra 20 #33-58'));
  • runString([expression],[array]) Evaluates the expression and returns the result.
  • expression = is the expression to evaluate
  • array (optional). Indicates the values to use for the template. For example ['v1'=>10'], indicates the variable $v1 is equals to 10

directive

It sets a new directive (command) that runs on compile time.

$blade->directive('datetime', function ($expression) {
    return "<?php echo ($expression)->format('m/d/Y H:i'); ?>";
});
@datetime($now)

directiveRT

It sets a new directive (command) that runs on runtime time.

$blade->directiveRT('datetimert', function ($expression) {
    echo $expression->format('m/d/Y H:i');
});

@datetimert($now)

BLADEONE_MODE (global constant) (optional)

It defines the mode of compilation (via global constant) See setMode(mode) for more information.

define("BLADEONE_MODE",BladeOne::MODE_AUTO);

  • BLADEONE_MODE Is a global constant that defines the behaviour of the engine.
  • Optionally, you could use $blade->setMode(BladeOne::MODE_AUTO);

Template tags

Template Inheritance

In the master page (layout)

|Tag|Note| |---|---| |@section('sidebar')|Start a new section| |@show|Indicates where the content of section will be displayed| |@yield('title')|Show here the content of a section|

Using the master page (using the layout)

|Tag|Note| |---|---| |@extends('layouts.master')|Indicates the layout to use| |@section('title', 'Page Title')|Sends a single text to a section| |@section('sidebar')|Start a block of code to send to a section| |@endsection|End a block of code|

Note :(*) This feature is in the original documentation but its not implemented neither its required. May be its an obsolete feature.

variables

|Tag|Note| |---|---| |{{$variable1}}|show the value of the variable using htmlentities (avoid xss attacks)| |@{{$variable1}}|show the value of the content directly (not evaluated, useful for js)| |{!!$variable1!!}|show the value of the variable without htmlentities (no escaped)| |{{ $name or 'Default' }}|value or default| |{{Class::StaticFunction($variable)}}|call and show a function (the function should return a value)|

logic

|Tag|Note| |---|---| |@if (boolean)|if logic-conditional| |@elseif (boolean)|else if logic-conditional| |@else|else logic| |@endif|end if logic| |@unless(boolean)|execute block of code is boolean is false|

loop

@for($variable;$condition;$increment) / @endfor

_Generates a loop until the condition is meet and the variable is incremented for each loop_

|Tag|Note|Example| |---|---|---| |$variable|is a variable that should be initialized.|$i=0| |$condition|is the condition that must be true, otherwise the cycle will end.|$i<10| |$increment|is how the variable is incremented in each loop.|$i++|

Example:

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

Returns:

The current value is 0
The current value is 1
The current value is 2
The current value is 3
The current value is 4
The current value is 5
The current value is 6
The current value is 7
The current value is 8
The current value is 9

@inject('variable name', 'namespace')

@inject('metric', 'App\Services\MetricsService')
<div>
    Monthly Revenue: {{ $metric->monthlyRevenue() }}.
</div>

By default BladeOne creates a new instance of the class 'variable name' inside 'namespace' with the parameterless contructor.

To override the logic used to resolve injected classes, pass a function to setInjectResolver.

Example with Symphony Dependency Injection.

$containerBuilder = new ContainerBuilder();
$loader = new XmlFileLoader($containerBuilder, new FileLocator(__DIR__));
$loader->load('services.xml');

$blade->setInjectResolver(function ($namespace, $variableName) use ($loader) {
    return $loader->get($namespace);
});

@foreach($array as $alias) / @endforeach

Generates a loop for each values of the variable.

|Tag|Note|Example| |---|---|---| |$array|Is an array with values.|$countries| |$alias|is a new variable that it stores each interaction of the cycle.|$country|

Example: ($users is an array of objects)

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

Returns:

This is user 1
This is user 2

@forelse($array as $alias) / @empty / @endforelse

Its the same than foreach but jumps to the @empty tag if the array is null or empty

|Tag|Note|Example| |---|---|---| |$array|Is an array with values.|$countries| |$alias|is a new variable that it stores each interaction of the cycle.|$country|

Example: ($users is an array of objects)

@forelse($users as $user)
    <li>{{ $user->name }}</li>
@empty
    <p>No users</p>
@endforelse

Returns:

John Doe
Anna Smith

@while($condition) / @endwhile

Loops until the condition is not meet.

|Tag|Note|Example| |---|---|---| |$condition|The cycle loops until the condition is false.|$counter<10|

Example: ($users is an array of objects)

@set($whilecounter=0)
@while($whilecounter<3)
    @set($whilecounter)
    I'm looping forever.<br>
@endwhile

Returns:

I'm looping forever.
I'm looping forever.
I'm looping forever.

@splitforeach($nElem,$textbetween,$textend="") inside @foreach

This functions show a text inside a @foreach cycle every "n" of elements. This function could be used when you want to add columns to a list of elements. NOTE: The $textbetween is not displayed if its the last element of the last. With the last element, it shows the variable $textend

|Tag|Note|Example| |---|---|---| |$nElem|Number of elements|2, for every 2 element the text is displayed| |$textbetween|Text to show|'</tr><tr>'| |$textend|Text to show|'</tr>'|

Example: ($users is an array of objects)

<table border="1">
<tr>
@foreach($drinks7 as $drink)
    <td>{{$drink}}</td>
    @splitforeach(2,'</tr><tr>','</tr>')
    @endforeach
</table>

Returns a table with 2 columns.

@continue / @break

Continue jump to the next iteration of a cycle. @Break jump out of a cycle.

|Tag|Note|Example| |---|---|---|

Example: ($users is an array of objects)

@foreach($users as $user)
    @if($user->type == 1) // ignores the first user John Smith
    @continue
    @endif
    <li>{{ $user->type }} - {{ $user->name }}</li>

    @if($user->number == 5) // ends the cycle.
        @break
    @endif
@endforeach

Returns:

2 - Anna Smith

switch / case

_Example:(the indentation is not required)_

@switch($countrySelected)
    @case(1)
        first country selected<br>
    @break
    @case(2)
        second country selected<br>
    @break
    @defaultcase()
        other country selected<br>
@endswitch()

  • @switch. The first value is the variable to evaluate.
  • @case. Indicates the value to compare. It should be runs inside a @switch/@endswitch
  • @default. (optional) If not case is the correct then the block of @defaultcase is evaluated.
  • @break Break the case
  • @endswitch. End the switch.

Sub Views

|Tag|Note| |---|---| |@include('folder.template')|Include a template| |@include('folder.template',['some' => 'data'])|Include a template with new variables| |@each('view.name', $array, 'variable')|Includes a template for each element of the array| Note: Templates called folder.template is equals to folder/template

@include

It includes a template

You could include a template as follow:

<div>
    @include('shared.errors')
    <form>
        <!-- Form Contents -->
    </form>
</div>

You could also pass parameters to the template

@include('view.name', ['some' => 'data'])

@includeif

Additionally, if the template doesn't exist then it will fail. You could avoid it by using includeif

@includeIf('view.name', ['some' => 'data'])

@includefast

@Includefast is similar to @include. However, it doesn't allows parameters because it merge the template in a big file (instead of rely on different files), so it must be fast at runtime by using more space on the hard disk versus less call to read a file.

@includefast('view.name')

>This template runs at compile time, so it doesn't work with runtime features such as @if() @includefast() @endif()

Comments

|Tag|Note| |---|---| |{{-- text --}}|Include a comment|

Stacks

|Tag|Note| |---|---| |@push('elem')|Add the next block to the push stack| |@endpush|End the push block| |@stack('elem')|Show the stack|

@set (new for 1.5)

@set($variable=[value]) @set($variable) is equals to @set($variable=$variable+1) - $variable define the variable to add. If not value is defined the it adds +1 to a variable. - value (option) define the value to use.

Service Inject

|Tag|Note| |---|---| |@inject('metrics', 'App\Services\MetricsService')|Used for insert a Laravel Service|NOT SUPPORTED|

Asset Management

The next libraries are designed to work with assets (css, javascript, images and so on). While it's possible to show a asset without a special library but it's a challenge if you want to work with relative path using a MVC route.

For example, let's say the next example: http://localhost/img/resource.jpg

you could use the full path.

<img src='http://localhost/img/resource.jpg' />

However, it will fail if the server changes. So, you could use a relative path.

<img src='img/resource.jpg' />

However, it fails if you are calling the web http://localhost/controller/action/

because the browser will try to find the image at http://localhost/controller/action/img/resource.jpg instead of http://localhost/img/resource.jpg

So, the solution is to set a base url and to use an absolute or relative path

Absolute using @asset

<img src='@asset("img/resource.jpg")' />

is converted to

<img src='http://localhost/img/resource.jpg' />

Relative using @relative

<img src='@relative("img/resource.jpg")' />

is converted to (it depends on the current url)

<img src='../../img/resource.jpg' />

It is even possible to add an alias to resources. It is useful for switching from local to CDN.

$blade->addAssetDict('js/jquery.min.js','https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js');

so then

@asset('js/jquery.min.js')

returns

https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js

:file_folder: Example: BladeOne/examples/relative1/relative2/callrelative.php

@asset

It returns an absolute path of the resource.

@asset('js/jquery.js')

Note: it requires to set the base address as

$obj=new BladeOne();
$obj->setBaseUrl("https://www.example.com/urlbase/"); // with or without trail slash

> Security: Don't use the variables $SERVER['HTTP_HOST'] or $SERVER['SERVER_NAME'] unless the url is protected or the address is sanitized.

@resource

It's similar to @asset. However, it uses a relative path.

@resource('js/jquery.js')

Note: it requires to set the base address as

$obj=new BladeOne();
$obj->setBaseUrl("https://www.example.com/urlbase/"); // with or without trail slash

setBaseUrl($url)

It sets the base url.

$obj=new BladeOne();
$obj->setBaseUrl("https://www.example.com/urlbase/"); // with or without trail slash

getBaseUrl()

It gets the current base url.

$obj=new BladeOne();
$url=$obj->getBaseUrl(); 

addAssetDict($name,$url)

It adds an alias to an asset. It is used for @asset and @relative. If the name exists then $url is used.

$obj=new BladeOne();
$url=$obj->addAssetDict('css/style.css','http://....'); 

Extensions Libraries (optional)

BladeOneHtml Documentation

BladeOneCache Documentation

BladeOneLang Documentation

Definition of Blade Template

https://laravel.com/docs/5.6/blade

Differences between Blade and BladeOne

  • Laravel's extension removed.
  • Dependencies to other class removed (around 30 classes).
  • The engine is self-contained.
  • Setter and Getters removed. Instead, we are using the PHP style (public members).
  • BladeOne doesn't support static calls.

Differences between Blade+Laravel and BladeOne+BladeOneHTML

Instead of use the Laravel functions, for example Form::select

{{Form::select('countryID', $arrayCountries,$countrySelected)}}

We have native tags as @select,@item,@items and @endselect

@select('countryID')
    @item('0','--Select a country--',$countrySelected)
    @items($arrayCountries,'id','name',$countrySelected)
@endselect()

This new syntaxis add an (optionally) a non-selected row. Also, BladeOneHTML adds multiple select, fixed values (without array), grouped select and many more.

Version

  • 2018-10-25 3.17 Halloween version. Now if the command doesn´t exist,for example @media @font-face and such, it doesn't show the error but returns the same text as verbatim.
  • 2018-10-25 3.16 Fixed an error with compile() when it's called with information.
  • - Now compile() returns true or false
  • - isExpected() has an optional argument.
  • - getCompiledFile() and getTemplateFile() now uses the default template ($this->fileName) if the arg is empty (null or '')
  • - arguments $fileName are now called $templateName because $filename is not a filename (temp/file.blade.php) but the name of the template (temp.file)
  • 2018-10-22 3.15 Fixed an error if _e() is called by an array or object.
  • 2018-10-09 3.14 Added @includefast
  • 2018-10-06 3.13 Added @relative, setBaseUrl(),getBaseUrl() and addAssetDict(). @asset is changed, now it allows dictionary. $baseUrl is not public anymore
  • 2018-09-29 3.12 Added the function setPath so we can change the path of the templates/compile files at runtime.
  • 2018-09-21 3.11 @includeif fixed.
  • 2018-09-21 3.10 Testing travis.
  • 2018-09-16 3.9 Added unit test (gamification) and travis :rocket:
  • 2018-09-01 3.8 Sorry Blade class,but you must go. \eftec\bladeone\BladeOneBlade.php is no-more so the static call and the instance. (#47)[https://github.com/EFTEC/BladeOne/issues/47] it was the last straw.
  • 2018-08-29 3.7 phpdoc block reduced. "To do" comments deleted. Fixed issue (#44)[https://github.com/EFTEC/BladeOne/issues/44]
  • 2018-08-24 3.5 Some fixes.
  • 2018-08-16 3.4 Custom if,@php tag and some fixes with @switch
  • 2018-08-08 3.3 Set extensions, constants and blade mode.
  • 2018-08-05 3.2 Fixed composer's problem
  • 2018-07-27 3.1 custom directive and directivert(runtime).
  • 2018-07-12 3.0 BladeOneLogic now is fused with BladeOne. And a lot of new changes.
  • 2018-07-11 2.4 Some fixes, new tags @json(var),@isset($records),@endisset,@includewhen,@includefirst,@prepend,@endprepend,@empty,@endempty,@append
  • 2018-06-12 2.3.3 Reorder folders.
  • 2018-06-11 2.3.2 Fixed bladeonehtml to allows readonly value.
  • 2018-05-06 2.3.1 Fixed a problem with @verbatim. Add the method runString for evaluating a function
  • 2018-04-13 2.3 The end result clean spaces. PHPDoc cleaned (checked with PHPStorm 2018.1). Fixed some typos (sorry about that).
  • 2017-12-18 Added BladeOneLang
  • 2017-12-14 2.2 Added @asset
  • 2017-10-20 2.1 Fixed with @parent Fixed @item (BladeOneHtml). Now, it considers null and 0 as different. Fixed foreach bug when the name of the variable contains the letters 'as' for example @foreach($listAsFast as $v)
  • 2017-09-28 2.0 Some fixes there and here.
  • 2017-07-21 1.9 Components and Slots. Note: I'm not really convinced in its usability.
  • 2017-05-24 1.8 Maintenance. Now, it runs with or without mb_string module
  • 2017-04-09 1.8 Creates directory automatically. Some fixes. Add new feature @splitforeach.
  • 2017-02-20 1.6 More cleanups. Refactored file, image, and other tags.
  • 2016-08-14 1.6 Some cleanups. Add new documentation
  • 2016-07-03 1.5 New features such as @set command
  • 2016-06-24 1.4 Updates extensions. Now it uses strut instead of classes. Added a new extension BladeOneCache.
  • 2016-06-12 1.3 Lots of clean up. I removed some unused parameters. I fixed a problem with forced in BladeOne. I separate the doc per extension.
  • 2016-06-10 1.2 New changes. Added namespaces (for autocomplete and compatibility with Composer)
  • 2016-06-09 1.1 Some fine tune.
  • 2016-06-09 1.0 Version. Most works. Added extensions and error control with a tag are not defined.
  • 2016-06-08 0.2. Beta First publish launch.

Changes between 2.x and 3.0

  • @defaultcase now is called @default (BladeOneLogic)
  • @break is now required for @switch/@case
  • BladeOneLogic is now merged with BladeOne. BladeOneLogic is discontinued.
  • New tags of security (optional).
  • New tags for injection

todo

  • @section / @show versus @endsection
  • hello@@world fails to render hello@world. However, hello @@world render hello@world.
  • extends bug. If you use extends then, every content after the last @endsetion will be rendered at the top of the page. Solution: avoid to add any content after the last @endsection,including spaces and empty lines.
  • Some functionalities are not available for php lower than 7.0.

bad example:

@extends("_shared.htmltemplate")
@section("content")
@endsection
this is a bug

result:

this is a bug
<!DOCTYPE html>
<html>
   <head>....</head>
   <body>....</body>
</html>

bad too: (check the empty line at the bottom). This is not as bad but a small annoying.

@endsection(line carriage)
(empty line)

good:

@endsection

SourceGuardian

This library is compatible with SourceGuardian.

>SourceGuardian provides full PHP 4, PHP 5 and PHP 7 support including the latest PHP 7.2 along with many other protection and encryption features.

However:

  • You must avoid to encode the template folder (copy unencoded the views folder).
  • Optionally, you must avoid to encode the compiled folder because the files could be replaced by Bladeone. Also, you could runs BladeOne in mode BladeOne::MODE_FAST and to encode the compile folder)

So, \view* folder = copy unencoded. \compiled* folder (BladeOne::MODE_FAST)= php/html script (encode) \compiled folder* (anything but BladeOne::MODE_FAST)= skip files (because it will be replaced) (everything else)* = php/html script (encode)

I don't know about the compatibility of Ioncube or Zend Guard I don't own a license of it.

Collaboration

You are welcome to use it, share it, ask for changes and whatever you want to. Just keeps the copyright notice in the file.

Future

  • Blade locator/container

Missing

Some features are missing because they are new, or they lacks of documentation or they are specific for laravel (then, they are useless without it)

  • Laravel's own commands. Reason: This library is free of Laravel
  • ~~Custom if. Reason: It is dangerous and odds.~~ DONE
  • blade extension Reason: Extensions (that is part of the code, not in the template) is managed differently on BladeOne.
  • ~~@php. Pending. I'm not so sure to implement this one. If you are using this one, then you are doing it wrong.~~ DONE
  • ~~@canany. Pending. :baby_chick:~~ DONE
  • ~~@can ( https://laravel.com/docs/5.6/authorization ). Pending~~ DONE
  • ~~@cannot. Pending~~ DONE
  • ~~@elseauth. Pending~~ DONE
  • ~~@elseguest. Pending~~ DONE
  • ~~@dump. Done. Ugly but it is done~~ DONE
  • ~~@elsecan. Pending~~ DONE
  • ~~@elsecanany. Pending :baby_chick:~~ DONE
  • ~~@elsecannot. Pending~~ DONE
  • ~~@endcanany. Pending :baby_chick:~~ DONE
  • ~~@endcannot. Pending~~ DONE
  • ~~@endunless. Pending~~ DONE
  • ~~@csrf. Pending~~ DONE
  • ~~@dd. Done. Ugly but it is done too.~~ DONE
  • ~~@method. Pending~~ DONE

License

MIT License. BladeOne (c) 2016-2018 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)

  Files folder image Files  
File Role Description
Files folder imagedocs (1 file)
Files folder imageexamples (24 files, 7 directories)
Files folder imagelib (7 files)
Files folder imagetests (12 files, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file BladeOneCache.md Data Auxiliary data
Accessible without login Plain text file BladeOneHtml.md Data Auxiliary data
Accessible without login Plain text file BladeOneLang.md Data Auxiliary data
Accessible without login Plain text file BladeOneLogic.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file readme.template.md Doc. Documentation

  Files folder image Files  /  docs  
File Role Description
  Accessible without login Image file cleaning.gif Icon Icon image

  Files folder image Files  /  examples  
File Role Description
Files folder imagecompiled (1 file)
Files folder imageimg (1 file)
Files folder imagejs (1 file)
Files folder imagelang (3 files)
Files folder imagerelative1 (1 directory)
Files folder imageservice (1 file)
Files folder imageviews (15 directories)
  Accessible without login Plain text file compilefile.php Example Example script
  Accessible without login Plain text file examplerelative.php Example Example script
  Accessible without login Plain text file test2.php Example Example script
  Accessible without login Plain text file test24.php Example Example script
  Accessible without login Plain text file test3.php Example Example script
  Accessible without login Plain text file testauth.php Example Example script
  Accessible without login Plain text file testbootstrap4.php Example Example script
  Accessible without login Plain text file testcomponent.php Example Example script
  Accessible without login Plain text file testComposer.php Example Example script
  Plain text file testcustom.php Class Class source
  Accessible without login Plain text file testcustomif.php Example Example script
  Accessible without login Plain text file testdirective.php Example Example script
  Plain text file testextension.php Class Class source
  Accessible without login Plain text file testincludefast.php Example Example script
  Accessible without login Plain text file testincludeif.php Example Example script
  Plain text file testinject.php Class Class source
  Plain text file testinjectcustom.php Class Class source
  Accessible without login Plain text file testjson.php Example Example script
  Plain text file testlang.php Class Class source
  Plain text file testloop.php Class Class source
  Plain text file testsecurity.php Class Class source
  Accessible without login Plain text file testsmall.php Example Example script
  Accessible without login Plain text file testswitch.php Example Example script
  Accessible without login Plain text file testtoken.php Example Example script

  Files folder image Files  /  examples  /  compiled  
File Role Description
  Accessible without login Plain text file note.txt Doc. Documentation

  Files folder image Files  /  examples  /  img  
File Role Description
  Accessible without login Image file cleaning.gif Icon Icon image

  Files folder image Files  /  examples  /  js  
File Role Description
  Accessible without login Plain text file jquery.min.js Data Auxiliary data

  Files folder image Files  /  examples  /  lang  
File Role Description
  Accessible without login Plain text file es.php Aux. Auxiliary script
  Accessible without login Plain text file fr.php Aux. Auxiliary script
  Accessible without login Plain text file jp.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  relative1  
File Role Description
Files folder imagerelative2 (1 file)

  Files folder image Files  /  examples  /  relative1  /  relative2  
File Role Description
  Accessible without login Plain text file callrelative.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  service  
File Role Description
  Plain text file Metric.php Class Class source

  Files folder image Files  /  examples  /  views  
File Role Description
Files folder imageif (2 files)
Files folder imageLang (1 file)
Files folder imagerelative (1 file)
Files folder imageShared (1 file)
Files folder imageTest (17 files, 1 directory)
Files folder imageTest2 (4 files)
Files folder imageTest3 (1 file)
Files folder imageTestBS (1 file)
Files folder imageTestCache (1 file)
Files folder imageTestComponent (2 files)
Files folder imageTestCustom (1 file)
Files folder imageTestExtension (1 file)
Files folder imageTestJSon (1 file)
Files folder imageTestSecurity (1 file)
Files folder imagewidgets (1 file)

  Files folder image Files  /  examples  /  views  /  if  
File Role Description
  Accessible without login Plain text file if.blade.php Aux. Auxiliary script
  Accessible without login Plain text file includeme.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  Lang  
File Role Description
  Accessible without login Plain text file test.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  relative  
File Role Description
  Accessible without login Plain text file relative.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  Shared  
File Role Description
  Accessible without login Plain text file newlayout.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  Test  
File Role Description
Files folder imageInnerView (1 file)
  Accessible without login Plain text file child.blade.php Aux. Auxiliary script
  Accessible without login Plain text file hello.blade.php Aux. Auxiliary script
  Accessible without login Plain text file hello2.blade.php Aux. Auxiliary script
  Accessible without login Plain text file includefast.blade.php Aux. Auxiliary script
  Accessible without login Plain text file inject.blade.php Aux. Auxiliary script
  Accessible without login Plain text file inject2.blade.php Aux. Auxiliary script
  Accessible without login Plain text file layout.blade.php Aux. Auxiliary script
  Accessible without login Plain text file loop.blade.php Aux. Auxiliary script
  Accessible without login Plain text file master.blade.php Aux. Auxiliary script
  Accessible without login Plain text file masterappend.blade.php Aux. Auxiliary script
  Accessible without login Plain text file Small.blade.php Aux. Auxiliary script
  Accessible without login Plain text file switch.blade.php Aux. Auxiliary script
  Accessible without login Plain text file test24.blade.php Aux. Auxiliary script
  Accessible without login Plain text file test3.blade.php Aux. Auxiliary script
  Accessible without login Plain text file testappend.blade.php Aux. Auxiliary script
  Accessible without login Plain text file testdump.blade.php Aux. Auxiliary script
  Accessible without login Plain text file token.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  Test  /  InnerView  
File Role Description
  Accessible without login Plain text file name.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  Test2  
File Role Description
  Accessible without login Plain text file auth.blade.php Aux. Auxiliary script
  Accessible without login Plain text file directive.blade.php Aux. Auxiliary script
  Accessible without login Plain text file include.blade.php Aux. Auxiliary script
  Accessible without login Plain text file template.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  Test3  
File Role Description
  Accessible without login Plain text file customif.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  TestBS  
File Role Description
  Accessible without login Plain text file hellobootstrap.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  TestCache  
File Role Description
  Accessible without login Plain text file hellocache.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  TestComponent  
File Role Description
  Accessible without login Plain text file alert.blade.php Aux. Auxiliary script
  Accessible without login Plain text file component.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  TestCustom  
File Role Description
  Accessible without login Plain text file test.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  TestExtension  
File Role Description
  Accessible without login Plain text file helloextensions.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  TestJSon  
File Role Description
  Accessible without login Plain text file example.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  TestSecurity  
File Role Description
  Accessible without login Plain text file test.blade.php Aux. Auxiliary script

  Files folder image Files  /  examples  /  views  /  widgets  
File Role Description
  Accessible without login Plain text file ckeditor.blade.php Aux. Auxiliary script

  Files folder image Files  /  lib  
File Role Description
  Plain text file BladeOne.php Class Class source
  Plain text file BladeOneCache.php Class Class source
  Plain text file BladeOneCacheRedis.php Class Class source
  Plain text file BladeOneCustom.php Class Class source
  Plain text file BladeOneHtml.php Class Class source
  Plain text file BladeOneHtmlBootstrap.php Class Class source
  Plain text file BladeOneLang.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageresources (1 directory)
  Plain text file AbstractBladeTestCase.php Class Class source
  Plain text file AuthTest.php Class Class source
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Plain text file CompilationTest.php Class Class source
  Plain text file EachTest.php Class Class source
  Plain text file ExtendsTest.php Class Class source
  Plain text file IfTest.php Class Class source
  Plain text file IncludeTest.php Class Class source
  Plain text file LoopTest.php Class Class source
  Plain text file NoEscapeTest.php Class Class source
  Plain text file SwitchTest.php Class Class source
  Plain text file VariablesTest.php Class Class source

  Files folder image Files  /  tests  /  resources  
File Role Description
Files folder imagetemplates (4 directories)

  Files folder image Files  /  tests  /  resources  /  templates  
File Role Description
Files folder imagecompilation (3 files)
Files folder imageeach (4 files)
Files folder imageextends (3 files)
Files folder imageinclude (4 files)

  Files folder image Files  /  tests  /  resources  /  templates  /  compilation  
File Role Description
  Accessible without login Plain text file base.blade Data Auxiliary data
  Accessible without login Plain text file base.blade.php Aux. Auxiliary script
  Accessible without login Plain text file noescape.blade.php Aux. Auxiliary script

  Files folder image Files  /  tests  /  resources  /  templates  /  each  
File Role Description
  Accessible without login Plain text file base.blade.php Aux. Auxiliary script
  Accessible without login Plain text file empty.blade.php Aux. Auxiliary script
  Accessible without login Plain text file empty_item.blade.php Aux. Auxiliary script
  Accessible without login Plain text file item.blade.php Aux. Auxiliary script

  Files folder image Files  /  tests  /  resources  /  templates  /  extends  
File Role Description
  Accessible without login Plain text file base.blade.php Aux. Auxiliary script
  Accessible without login Plain text file child.blade.php Aux. Auxiliary script
  Accessible without login Plain text file child_section.blade.php Aux. Auxiliary script

  Files folder image Files  /  tests  /  resources  /  templates  /  include  
File Role Description
  Accessible without login Plain text file base.blade.php Aux. Auxiliary script
  Accessible without login Plain text file if.blade.php Aux. Auxiliary script
  Accessible without login Plain text file subject.blade.php Aux. Auxiliary script
  Accessible without login Plain text file when.blade.php Aux. Auxiliary script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:316
This week:2
All time:7,068
This week:183Up
 User Ratings  
 
 All time
Utility:100%StarStarStarStarStarStar
Consistency:100%StarStarStarStarStarStar
Documentation:91%StarStarStarStarStar
Examples:91%StarStarStarStarStar
Tests:-
Videos:-
Overall:78%StarStarStarStar
Rank:56