drago-ex / simple
Easy configuration for single-page sites.
v2.1.0
2026-10-17 13:17 UTC
Requires
- php: >=8.3 <9
- latte/latte: ^3.0
- nette/http: ^3.0
- nette/robot-loader: ^4.0
Requires (Dev)
- nette/tester: ^2.5
- phpstan/phpstan: ^2.0
- phpstan/phpstan-nette: ^2.0
- tracy/tracy: ^2.10
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Easy configuration for single-page sites.
Requirements
- PHP >= 8.3, < 9
- Nette Framework
- Composer
Installation
composer require drago-ex/simple
Knowledge
- Latte: amazing template engine for PHP
- RobotLoader: comfortable autoloading
- Nette HTTP Component
- Tracy - PHP debugger
Latte
Drago\Simple\Latte is a Latte engine that passes $basePath to every template:
use Drago\Simple\Latte; $latte = new Latte; $latte->setTempDirectory(__DIR__ . '/../temp/latte');
<link rel="stylesheet" href="{$basePath}/css/style.css">
Traits
Session Trait
use Drago\Simple\Base\Session; // The session is created from the current request on the first call and then reused $this->session();
Message Trait
use Drago\Simple\Base\Message; // Save a message for the next page $this->flashMessage('Message...'); // Read the message; it is removed after reading, so it is shown only once $this->getFlashMessage();
Response Trait
use Drago\Simple\Base\Response; // Redirect to a URL; the script stops after the redirect is sent $this->redirect('#');
Controller Example
use Drago\Simple\Base\Message; use Drago\Simple\Latte; final class Home { use Message; public function __construct( private Latte $latte, ) { } public function render(): void { $this->latte->render(__DIR__ . '/templates/Home.latte', [ 'message' => $this->getFlashMessage(), ]); } }
<p n:if="$message">{$message}</p>
Forms
Install Nette Forms via Composer:
composer require nette/forms
Register the form tags in Latte:
$latte->addExtension(new Nette\Bridges\FormsLatte\FormsExtension);
Translator
Install the Translator via Composer:
composer require drago-ex/translator
Create the translator with your translation directory and choose the language from the request:
use Drago\Localization\Options; use Drago\Localization\Translator; use Drago\Localization\TranslatorFinder; use Nette\Http\RequestFactory; $options = new Options; $options->translateDirs = [__DIR__ . '/locale']; $translator = new Translator($options, new TranslatorFinder); $lang = (new RequestFactory)->fromGlobals()->detectLanguage(['en', 'cs']) ?? 'en'; $translator->setTranslate($lang); $latte->addExtension(new Latte\Essential\TranslatorExtension($translator->translate(...)));
Translations are then available in templates as {_'Hello'} or {$text|translate}.