PHP Classes
elePHPant
Icontem

BlitzTemplateControl: Process templates using the Blitz PHP extension

Recommend this page to a friend!
  Info   View files Example   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-09-19 (9 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
blitztemplatecontrol 0.6GNU General Publi...5.3PHP 5, Cache, Templates
Description Author

This class can process templates using the Blitz PHP extension.

It can creates an object of the Blitz extension to apply variables passed in an array to the class as parameter.

The class can take a one or more PHP scripts as templates to be processed.

The output can be cached in Redis database to avoid the over head of processing the templates again .

Name: Nic Latyshev <contact>
Classes: 3 packages by
Country: Russian Federation Russian Federation
Innovation award
Innovation award
Nominee: 1x

Details

BlitzTemplateControl

Wrapper for Blitz template PHP extensions. Realize many support templates store type: original separate tpl files, single php file and Redis cache suport. Also always preload all Blitz includes by this includes content.

Required

  • Blitz extension (https://github.com/alexeyrybak/blitz)
  • phpredis extension (https://github.com/phpredis/phpredis) if use cached mode

Usage

Just include class file, create templates, make your data and apply template

Directory structure

Separate TPL files mode

If you use separate templates files, ?reate a folder "TemplatesTPL" in the same place as the class file. Name of this folder set in public property 'relative_tpath_separates_blitz' in class. Templates for each set must be in the folder with the name of this set.

  • :file_folder: TemplatesTPL - :file_folder: SomeSetName - :page_facing_up: template_one.tpl - :page_facing_up: template_two.tpl

Single PHP-file mode

If you use single PHP-file mode with all set templates in one PHP-file with '$templates' array, create a folder "TemplatesPHP" in the same place as the class file. Name of this folder set in public property 'relative_tpath_singlefile_blitz' in class. Templates for each set must be in the one file with the name of this set + .tmpl.php

  • :file_folder: TemplatesPHP - :page_facing_up: SomeSetName.tmpl.php

Example

<?php 

include_once 'BlitzTemplateControl.class.php';

$data = [
	'authors' => [
		0 => ['fname'=>'Lev','lastname'=>'Tolstoi'],
		1 => ['fname'=>'Vladimir','lastname'=>'Nabokov'],
	],
]; 

/Use templates in one single file with php-array/
$tmplcontrol_in_single_file = new BlitzTemplateControl('SomeClass');

echo $tmplcontrol_in_single_file->apply('authors',$data);

/Use templates in separate files in folder/
$tmplcontrol_in_tpl_files = new BlitzTemplateControl('SomeClass',true);

echo $tmplcontrol_in_tpl_files->apply('authors',$data);

?>

Redis Cache

Also you can cache templates in Redis, there will be fully expanded templates, in which all inclusions are replaced by this content. Templates are stored in the HSET with a key name 'Template:'.SomeSetName.':'.md5(FILENAME).

In this mode, every time the templates are loaded, the date of modification of the files or file is checked, if any templates in the file are fresh than the data in the Redis, then the cache is updated with new TTL. If the templates in the files have not changed, then only the update key TTL

  Files folder image Files  
File Role Description
Files folder imageTemplatesPHP (1 file)
Files folder imageTemplatesTPL (1 directory)
Plain text file BlitzTemplateControl.class.php Class Class source
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  TemplatesPHP  
File Role Description
  Accessible without login Plain text file SomeClass.tmpl.php Aux. Auxiliary script

  Files folder image Files  /  TemplatesTPL  
File Role Description
Files folder imageSomeClass (2 files)

  Files folder image Files  /  TemplatesTPL  /  SomeClass  
File Role Description
  Accessible without login Plain text file authors.tpl Data Auxiliary data
  Accessible without login Plain text file authors_row_entry.tpl Data Auxiliary data

 Version Control Unique User Downloads  
 100%
Total:0
This week:0