How to use Nette & Latte in single-page website?
This is index.php:
index.php
<?php if (empty($template)) { require __DIR__ . '/Nette/loader.php'; $configurator = new Nette\Config\Configurator; $configurator->enableDebugger(__DIR__ . '/log'); // Enable Nette Debugger for error visualisation & logging $configurator->setTempDirectory(__DIR__ . '/temp'); $container = $configurator->createContainer(); // Create Dependency Injection container from config.neon file $template = $container->nette->createTemplate()->setFile(__FILE__); $template->db = new Nette\Database\Connection('sqlite:data/ps.sdb'); $template->render(); exit; } ?> <!DOCTYPE html> <html> <head> <title>Welcome</title> </head> <body> <div n:foreach="$db->table(events)->order(date) as $event"> <h4>{$event->name}</h4> <p>{$event->date|date:"j. n. Y"}</p> </div> ... </body> </html>
You can add $configurator->addConfig(__DIR__ . '/config/config.neon') before createContainer().
$configurator->addConfig(__DIR__ . '/config/config.neon')
createContainer()
Then you need to configure RobotLoader to load the class:
$configurator->createRobotLoader()->addDirectory(__DIR__ . '/app')