phalette/platte

Nette Latte template adapter for Phalcon

Fund package maintenance!
f3l1x

0.2 2015-09-15 11:04 UTC

This package is auto-updated.

Last update: 2024-11-08 07:11:47 UTC


README

Phalconist Build Status Code coverage Downloads this Month Latest stable HHVM Status

Combination of one of the best template engine Latte and pretty fast framework Phalcon.

Install

$ composer require phalette/platte:dev-master

Dependencies

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

  1. 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(...);
    }
}
  1. Register to LatteFatory
$factory = new LatteFactory();
$factory->addMacro(new MyUltraMacros);

Writing filters

  1. Define filters
final class MyUltraFilters
{
    public static function hi($name) 
    {
        return "Hi $name";
    }
}
  1. Register to LatteFatory
$factory = new LatteFactory();
$factory->addFilter('sayhi', ['MyUltraFilters', 'hi']);