PHP code example of ujpef / latte-view

1. Go to this page and download the library: Download ujpef/latte-view library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ujpef / latte-view example snippets


$engine = new \Latte\Engine\Engine();
$engine->setLoader(new \Latte\Loaders\FileLoader(__DIR__ . '/../templates/'));
$engine->setTempDirectory(__DIR__ . '/../cache');

$latteView = new \Ujpef\LatteView\LatteView($engine);

use Latte\Engine;
use Latte\Loaders\FileLoader;
use Ujpef\LatteView;

$container['view'] = function ($container) use ($settings) {
    $engine = new Engine();
    $engine->setLoader(new FileLoader(__DIR__ . '/../templates/'));
    $engine->setTempDirectory(__DIR__ . '/../cache');

    $latteView = new LatteView($engine);
    return $latteView;
};

$app->get('/[{name}]', function (Request $request, Response $response, $args) {
    $tplVars = [
        'variable' => 123
    ];
    return $this->view->render($response, 'index.latte', $tplVars);
})->setName('index');

use Latte\Engine;
use Latte\MacroNode;
use Latte\PhpWriter;
use Latte\Loaders\FileLoader;
use Ujpef\LatteView;

$container['view'] = function ($container) use ($settings) {
    $engine = new Engine();
    $engine->setLoader(new FileLoader(__DIR__ . '/../templates/'));
    $engine->setTempDirectory(__DIR__ . '/../cache');

    $latteView = new LatteView($engine);
    $latteView->addParam('router', $container->router);
    $latteView->addMacro('link', function (MacroNode $node, PhpWriter $writer) {
        if (strpos($node->args, ' ') !== false) {
            return $writer->write("echo \$router->pathFor(%node.word, %node.args);");
        } else {
            return $writer->write("echo \$router->pathFor(%node.word);");
        }
    });
    return $latteView;
};

$app->get('/test', function (Request $request, Response $response, $args) {
    //route implementation
})->setName('routeName');

$app->get('/test/{something}', function (Request $request, Response $response, $args) {
    //route implementation
})->setName('routeName');