PHP Classes

Laravel Blitz View Package: Facade to access template processing classes

Recommend this page to a friend!
  Info   View files Documentation   View files View files (17)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 13 This week: 1All time: 11,247 This week: 560Up
Version License PHP version Categories
laravel-blitz-facade 1.1.0MIT/X Consortium ...8Libraries, Templates, Design Patterns, P...
Description 

Author

This package provides a facade to access template processing classes.

It provides a facade class and a service class that exposes access to the Blitz template processing engine as a service for applications based on the Laravel framework.

The configuration of the options to use in the Blitz template engine is loaded from the a separate configuration script. It may contain option values to set the directory to load the template, the type of cache storage system, etc..

Picture of Nic Latyshev
Name: Nic Latyshev <contact>
Classes: 6 packages by
Country: Russian Federation Russian Federation
Age: 48
All time rank: 301082 in Russian Federation Russian Federation
Week rank: 411 Up22 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 2x

Documentation

Laravel Blitz View Package

Facade for Blitz template PHP extensions.

Required

  • Blitz extension (https://github.com/alexeyrybak/blitz)
  • If you want use Redis for cache compiled templates may required https://github.com/phpredis/phpredis extension or https://github.com/predis/predis class Redis cache type use Laravel Redis Facade, configured in your redis config.

Default cache type is "file", prepared templates store into laravel "storage/blitz_compiled" folder (may change in config). By default, caching is disabled, you may change "cache_enabled" to "true" in "config/blitz.php"

Installation For Laravel

Require this package with Composer

$ composer require nickyx3/blitz

Then run

$ php artisan vendor:publish --provider="NickyX3\Blitz\Providers\BlitzServiceProvider"

Configuration

Default configuration

    'templates_folder'      => 'blitz_view',
    'cache_type'            => 'file',
    'cache_enabled'         => false,
    'compiled_folder'       => 'blitz_compiled',
    'scope_lookup_limit'    => 8,
    'php_callbacks_first'   => 1,
    'namespace_finder'      => [
        'App\Helpers',
        'Illuminate\Support',
        'Illuminate\Support\Facades'
    ]

Config parameters

  • templates_folder - where source templates relative to laravel resources folder
  • cache_type - 'file' or 'redis', default 'file'
  • cache_enabled - enabled or disabled caching, default 'false'
  • compiled_folder - where store cache relative to laravel storage folder, also if cache type 'redis' redis key is full path to compiled file in filesystem like 'file' cache type
  • scope_lookup_limit - blitz extension ini parameter
  • php_callbacks_first - blitz extension ini parameter
  • namespace_finder - in which namespace the template processor will look for classes specified in templates as callbacks. For example, you wrote in the template ```Lang::get('DefaultTitle')```. The processor will find the first matching class in these namespaces and expand it into a fully qualified class name with a namespace (```Illuminate\Support\Facades\Lang::get('DefaultTitle')```). If the class is not found, then the callback will be deleted.

Usage

Example Controller

use NickyX3\Blitz\Facade\BlitzView;

Route::get('/', function () {
    return BlitzView::apply('example.blitz-extend',['title'=>'Blitz Title']);
});

Method `apply` returns `Illuminate\Http\Response`, also method `make` is alias for `apply`

Command

The command is also available to clear the template cache

$ php artisan blitz:clear

Exceptions

If Blitz generate error, throw custom BlitzException with integrated renderer. This exception will be rendered if your env `APP_DEBUG=true`, otherwise simple laravel error 500 with abort helper.

Template Syntax Features

Unlike Blitz, which can only do include, template "up" inheritance works like in Blade Engine. The following Blade directives are supported: `@yield`, `@extends`, `@section` and `@endsection` placed in an HTML comment tag. Also added Blade `@csrf` helper support, in HTML comment tag like `<!-- @csrf -->`or direct `@csrf`

Examples

  • "example/master.tpl" template
    <!DOCTYPE html>
    <html lang="en">
    <body>
    <!-- @yield('content') -->
    </body>
    </html>
    
  • "blitz-extend.tpl" template
    <!-- @extends('example.master') -->
    <!-- @section('content') -->
    <div class="child-template">this is template extends example/master.tpl</div>
    <!-- @endsection -->
    

How callbacks works?

  • Some Blitz directives like inline conditions with callbacks will be transform info full version, because callbacks not work in conditions
    {{ if($title,$title,Lang::get('DefaultTitle')) }}
    
    transform into
    
    {{ IF $title }}{{ $title }}{{ ELSE }}{{ Illuminate\Support\Facades\Lang::get('DefaultTitle') }}{{ END if-title }}
  • Full Blitz IF condition wth callback like this
    {{ IF App::currentLocale()=='en' }}
    currentLocale: {{ App::currentLocale() }}
    {{ ELSE }}
    currentLocale not 'en'
    {{ END }}
    
    will be transformed to this code in cached template
    
    {{ IF Illuminate\Support\Facades\App::currentLocale()=='en' }} currentLocale: {{ Illuminate\Support\Facades\App::currentLocale() }} {{ ELSE }} currentLocale not 'en' {{ END }}
    but after get "compiled" template all callbacks like that will be converted to variables on the fly
    
    {{ IF $callback_83e69f8a22cc276d050d93f63c89a290=='en' }} currentLocale: {{ $callback_83e69f8a22cc276d050d93f63c89a290 }} {{ ELSE }} currentLocale not 'en' {{ END }} where variable ```$callback_83e69f8a22cc276d050d93f63c89a290``` will be set result of eval ```Illuminate\Support\Facades\App::currentLocale();```. If there are callbacks in the template that match the callbacks in the condition, they will also be replaced with this variable in order not to call the callback multiple times

Have fun!

Perhaps the code is not very good, I'm new to Laravel and also very poorly documented because I'm going on vacation. Maybe I'll make detailed comments later :-)

Additions and corrections welcome


  Files folder image Files  
File Role Description
Files folder imagesrc (1 file, 8 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageconfig (1 file)
Files folder imageConsole (1 directory)
Files folder imageExceptions (2 files)
Files folder imageFacade (1 file)
Files folder imageProviders (1 file)
Files folder imagepublic (1 file)
Files folder imageresources (1 directory)
Files folder imageSupport (2 files, 1 directory)
  Plain text file BlitzMaker.php Class Class source

  Files folder image Files  /  src  /  config  
File Role Description
  Accessible without login Plain text file blitz.php Conf. Configuration script

  Files folder image Files  /  src  /  Console  
File Role Description
Files folder imageCommands (1 file)

  Files folder image Files  /  src  /  Console  /  Commands  
File Role Description
  Plain text file BlitzClearCache.php Class Class source

  Files folder image Files  /  src  /  Exceptions  
File Role Description
  Plain text file BlitzException.php Class Class source
  Plain text file BlitzHandlerException.php Class Class source

  Files folder image Files  /  src  /  Facade  
File Role Description
  Plain text file BlitzView.php Class Class source

  Files folder image Files  /  src  /  Providers  
File Role Description
  Plain text file BlitzServiceProvider.php Class Class source

  Files folder image Files  /  src  /  public  
File Role Description
  Accessible without login Plain text file exception.css Data Auxiliary data

  Files folder image Files  /  src  /  resources  
File Role Description
Files folder imageblitz_view (1 directory)

  Files folder image Files  /  src  /  resources  /  blitz_view  
File Role Description
Files folder imageexample (2 files)

  Files folder image Files  /  src  /  resources  /  blitz_view  /  example  
File Role Description
  Accessible without login Plain text file blitz-extend.tpl Data Auxiliary data
  Accessible without login Plain text file master.tpl Data Auxiliary data

  Files folder image Files  /  src  /  Support  
File Role Description
Files folder imageCache (3 files)
  Plain text file BlitzTemplateCompiler.php Class Class source
  Plain text file BlitzTemplateLoader.php Class Class source

  Files folder image Files  /  src  /  Support  /  Cache  
File Role Description
  Plain text file BlitzTemplateCacheFile.php Class Class source
  Plain text file BlitzTemplateCacheInterface.php Class Class source
  Plain text file BlitzTemplateCacheRedis.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:13
This week:1
All time:11,247
This week:560Up