PHP code example of eftec / bladeone

1. Go to this page and download the library: Download eftec/bladeone library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eftec / bladeone example snippets


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

// some php code
ShowTemplate();

$name=@$_GET['name'];
echo "my name is ".$name;
 // index.php
$name=@$_GET['name'];
 
// template.php
echo "my name is ".$name;
 
 // template.php
echo "my name is ".html_entities($name);
 
// template.blade.php
My name is {{$name}}
 // template.php
<select>
    <? foreach($countries as $c) { 
 // template.blade.php
<select>
    @foreach($countries as $c)
        <option value={{$c->value}} >{{echo html_entities($c->text)}}</option>
    @nextforeach
</select>
 // template.blade.php
@select('id1')
    @items($countries,'value','text','','')
@endselect()

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

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

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

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

use eftec\bladeone\BladeOne;

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

use eftec\bladeone\BladeOne;

$blade = new BladeOne(); // MODE_DEBUG allows to pinpoint troubles.
echo $blade->setView('hello')    // it sets the view to render
           ->share(array("variable1"=>"value1")) // it sets the variables to sends to the view            
           ->run(); // it calls /views/hello.blade.php

$blade=new BladeOne();
$blade->pipeEnable=true; // pipes are disable by default so it must be enable.
echo $blade->run('template',['name'=>'Jack Sparrow']);

 {{$name}}  or {!! $name !!} // Jack Sparrow

 {{$name | strtoupper}} // JACK SPARROW 

 {{$name | strtoupper | substr:0,5}} // JACK



Use eftec\bladeone;

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

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

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

namespace namespace1\namespace2 {
    class SomeClass {
        public static function Method($arg='') {
            return "hi world";
        }
    }
}

    $blade = new BladeOne();
    // with the method addAliasClasses
    $blade->addAliasClasses('SomeClass', '\namespace1\namespace2\SomeClass');
    // with the setter setAliasClasses
    $blade->setAliasClasses(['SomeClass'=>'\namespace1\namespace2\SomeClass']);
    // or directly in the field
    $blade->aliasClasses=['SomeClass'=>'\namespace1\namespace2\SomeClass'];
__DIR__/views
__DIR__/compiles

$blade=BladeOne::$instance;
echo $blade->run("hello",array("variable1"=>"value1")); // it calls /views/hello.blade.php
shell
php vendor/lib/eftec/bladeone/lib/BladeOne.php -clearcompile
shell
php vendor/lib/eftec/bladeone/lib/BladeOne.php -check