mezon PHP Template Engine: Process templates to generate HTML Web pages

Recommend this page to a friend!
  Info   View files Documentation   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-11-18 (11 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 41 This week: 1All time: 10,198 This week: 194Up
Version License PHP version Categories
mezon-template-engin 1.0.0MIT/X Consortium ...5HTML, PHP 5, Templates
Description Author

This package can process templates to generate HTML Web pages.

It can take a string with a template and processes it replacing variable marks passed as parameter values to the engine template processing functions.

The package can also use a class that gathers HTML page external resources like JavaScript and CSS stylesheet files and can generate page head tags to include those external resources in the page output.

Picture of Alexey Dodonov
  Performance   Level  
Name: Alexey Dodonov <contact>
Classes: 46 packages by
Country: Russian Federation Russian Federation
Age: ???
All time rank: 212262 in Russian Federation Russian Federation
Week rank: 39 Up4 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 8x


Template engine


Template engine provides template compilation routine with variables, loops and other programming abstractions.

Loading resources

Mezon has a simple storage wich stores CSS and JS files. When page is rendered, template engine accessing it and fetching files to put in the 'head' tag of the rendered page.

Storage is globally accessed. So any componen can add it's own resources to the page.

It can be done in this way:

$TemplateResources = new TemplateResources(); // getting access to the global storage

$TemplateResources->add_css_file( './res/test.css' ); // additing CSS file
$TemplateResources->add_js_file( './include/js/test.js' ); // additing JS file

    array( './res/test1.css' , './res/test2.css' )
); // additing CSS files
    array( './include/js/test1.js' , './include/js/test2.js' )
); // additing JS files

Resource storage is quite intilligent so you can't add many files with the same paths.

$TemplateResources = new TemplateResources(); // getting access to the global storage

$TemplateResources->add_css_file( './res/test.css' ); // additing CSS file
$TemplateResources->add_css_file( './res/test.css' ); // no file will be added

But this way of additing resources is quite low level and it may be inconvinient for large number of resource files. So we have created assets. The documentation about it can be read here

Page compilation

TemplateEngine class provides content compilation routine. This function is called TemplateEngine::print_record( $String , $Data ) wich replaces all variables {variable-name} with values from $Data.

// outputs "v1 v2"
print( TemplateEngine::print_record( 
    '{var1} {var2}' , array( 'var1' => 'v1' , 'var2' => 'v2' ) 
) );

// or object
$Object = new stdClass();
$Object->var1 = 'v1';
$Object->var2 = 'v2';

// outputs "v1 v2"
print( TemplateEngine::print_record( 
    '{var1} {var2}' , $Object 
) );

// $Data may contain nested arrays or objects
// outputs "v1 v2 v3"
print( TemplateEngine::print_record( 
    '{var1} {var2} {var3}' , array( $Object , array( 'var3' => 'v3' ) )
) );

Template variables

You can use template variables bounded by '{' and '}' symbols.

For example:

Extended page compilation

You may also use loopes in your templates.

For example:

$Engine = new TemplateEngine();
$Engine->set_page_var( 'var1' , 'value1' );
$Engine->set_page_var( 'var2' , 'value2' );

$Content = '{var1} & {var2}';
print( $Engine->compile_page_vars( $Content ) ); // outputs "value1 value2"

And the output will be:

row : 1<br>
row : 2<br>
row : Last<br>
  Files folder image Files  
File Role Description
Files folder imageTests (3 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Plain text file Parser.php Class Class source
Plain text file Parser2.php Class Class source
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file Doc. Documentation
Plain text file TemplateEngine.php Class Class source

  Files folder image Files  /  Tests  
File Role Description
  Plain text file ParserUnitTest.php Class Class source
  Plain text file TemplateEngine2UnitTest.php Class Class source
  Plain text file TemplateEngineUnitTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:1
All time:10,198
This week:194Up
For more information send a message to info at phpclasses dot org.