dev-master
9999999-devFast and flexible template engine
MIT
The Development Requires
by Vitkovskii Vladimir
0.1.0
0.1.0.0
MIT
The Development Requires
by Vitkovskii Vladimir
Fast and flexible template engine
Fast and flexible template engine, (*1)
See example, (*2)
Use composer to install, (*3)
$jte = new Jte(__DIR__ . '/templates', ['useCache' => true, 'dir' => __DIR__ . '/cache/']); echo $jte->render('template.jte', 'main', ['param1' => 'value1', 'param2' => 'value2']);
Template consists of sections. There are three section types:, (*4)
This section is executed then template is booting. Body of the section is pure PHP code., (*5)
If you want template extends another, you can specify it in this section:, (*6)
boot { extend('base.jte'); }
Dynamic inheritance:, (*7)
boot { extend(param('parent')); }
More complex:, (*8)
boot { if (param('some') % 2 == 0) { extend('foo.jte'); } else { extend('baz.jte'); } }
Block is an independent chunk of HTML or something else :), (*9)
markup some_block_name { <html> <head> </head> <body> </body> </html> }
You can include references to another blocks into block:, (*10)
markup some_block_name { <html> <head> </head> <body> [[ body_block ]] </body> </html> }
Also you can include tree of blocks:, (*11)
markup some_block_name { <html> <head> </head> <body> [[ body_block ]] {{ <div> [[ menu_block ]] </div> <div> [[ footer_block ]] </div> }} </body> </html> }
If you want to include passed param into template do this:, (*12)
markup footer { <div> User count: [[ user_count_block = user_count_param ]] </div> }
Or anonymous variant:, (*13)
markup footer { <div> User count: [[ =user_count_param ]] </div> }
With this block you can dynamically generate block contents from params or another blocks. Body of this block is pure PHP code., (*14)
Replace block with passed param:, (*15)
markup footer {User count: [[ user_count_block ]]} logic footer { replace('user_count_block')->with(param('user_count')); }
Replace block with another block:, (*16)
markup item { Foo :) } markup footer {[[ footer_content ]]} logic footer { replace('footer_content')->with(block('item')); }
Replace block with iterator:, (*17)
markup item { Foo :) [[ =count ]] } markup footer {[[ footer_content ]]} logic footer { replace('footer_content')->with(iterator([1, 2, 3], function($item, $count) { return block('item', ['count' => $count]); })); }
Self replacement:, (*18)
logic menu { replace('menu_items')->with(iterator(param('menu'), function($item, $count) { if ($count % 2 == 1) { $class = 'bg-1'; } else { $class = 'bg-2'; } $item['class'] = $class; return self($item); })); } markup menu {
Fast and flexible template engine
MIT
MIT