phalette / platte
Nette Latte template adapter for Phalcon
Fund package maintenance!
f3l1x
Installs: 57 182
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 3
Forks: 1
Open Issues: 1
Requires
- php: >= 5.6.0
- ext-phalcon: ~2.0.0
- latte/latte: ~2.3.0
Requires (Dev)
- janmarek/mockista: dev-master
- nette/tester: ~1.5
- phalcon/devtools: ~2.0.0
This package is auto-updated.
Last update: 2024-12-08 07:19:06 UTC
README
Combination of one of the best template engine Latte and pretty fast framework Phalcon.
Install
$ composer require phalette/platte:dev-master
Dependencies
- PHP >= 5.5.0
- Latte >= 2.3.0
- Phalcon >= 2.0.0
Configuration
Register Platte as your next template engine
.
use Phalette\Platte\Latte\LatteFactory; use Phalette\Platte\LatteTemplateAdapter; $di->set('view', function () { $view = new View(); $view->registerEngines([ ".latte" => function ($view, $di) { $factory = new LatteFactory(); $factory->setTempDir(__DIR__ . '/cache'); return new LatteTemplateAdapter($view, $di, $factory); }, ]); return $view; });
Features from Phalcon
You can access variables in templates.
In extreme cases you can access $_di. But I really not recommend it.
Macros
Features from Nette
You can use all the great features from the Latte.
Latte Template Engine
See more on official documentation.
You can use macros and filters.
Macros
Classic macros
<ul> {foreach $users as $user} <li>{$user->name}</li> {/foreach} </ul>
N-macros
<ul n:foreach="$users as $user"> <li>{$user->name}</li> </ul>
Filters
{var $time => time()} It's {$time|date:'d.m.Y'} at {$time|date:'H:i:s'}
Latte Macros
See more on official documentation.
Latte Filters
See more on official documentation.
Features from your own
Writing macros
- Define macros
use Latte\Compiler; use Latte\Macros\MacroSet; use Phalette\Platte\Latte\MacroInstaller; final class MyUltraMacros extends MacroSet implements MacroInstaller { public static function install(Compiler $compiler) { $me = new static($compiler); $me->addMacro(...); } }
- Register to
LatteFatory
$factory = new LatteFactory(); $factory->addMacro(new MyUltraMacros);
Writing filters
- Define filters
final class MyUltraFilters { public static function hi($name) { return "Hi $name"; } }
- Register to
LatteFatory
$factory = new LatteFactory(); $factory->addFilter('sayhi', ['MyUltraFilters', 'hi']);