Recommend this page to a friend! |
Download .zip |
Info | Documentation | View files (10) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2020-11-18 (29 days ago) | Not yet rated by the users | Total: 31 This week: 1 | All time: 10,054 This week: 208 |
Version | License | PHP version | Categories | |||
mezon-template-engin 1.0.0 | MIT/X Consortium ... | 5 | HTML, PHP 5, Templates |
Description | Author | |
This package can process templates to generate HTML Web pages. |
|
Template engine provides template compilation routine with variables, loops and other programming abstractions.
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
$TemplateResources->add_css_files(
array( './res/test1.css' , './res/test2.css' )
); // additing CSS files
$TemplateResources->add_js_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
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' ) )
) );
You can use template variables bounded by '{' and '}' symbols.
For example:
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 |
File | Role | Description | ||
---|---|---|---|---|
Tests (3 files) | ||||
composer.json | Data | Auxiliary data | ||
composer.lock | Data | Auxiliary data | ||
Parser.php | Class | Class source | ||
Parser2.php | Class | Class source | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation | ||
TemplateEngine.php | Class | Class source |
Files | / | Tests |
File | Role | Description |
---|---|---|
ParserUnitTest.php | Class | Class source |
TemplateEngine2UnitTest.php | Class | Class source |
TemplateEngineUnitTest.php | Class | Class source |
mezon-template-engin-2020-11-18.zip 9KB | |
mezon-template-engin-2020-11-18.tar.gz 6KB | |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.