Search by

drago-ex / application

accgit

Extension for Nette Framework, providing reusable UI components, alert types, and flash message handling.

Package info

github.com/drago-ex/application

pkg:composer/drago-ex/application

Statistics

Installs: 5 533

Dependents: 11

Suggesters: 0

Stars: 0

Open Issues: 0

v4.0.0 2026-10-29 15:27 UTC

README

Base classes for Nette controls, templates and form factories, flash message types, and Latte widgets for flash messages, toasts and tables.

License: MIT PHP version Tests Coding Style

Requirements

  • PHP >= 8.3, < 9
  • Nette Framework
  • Composer
  • Bootstrap
  • Naja

Installation

composer require drago-ex/application

Project Tools copies the Latte widgets @flash-message, @table and @toast into app/Presentation/Accessory/Widget, where you adapt them.

ExtraControl

Extend Drago\Application\UI\ExtraControl instead of Nette\Application\UI\Control.

AJAX request

Shortcut for the presenter check:

$this->isAjax();

Presenter helpers

These methods call the corresponding presenter method, so they are useful when an action should affect the whole page rather than only the control.

$this->addRedirect('Homepage:default'); // Redirects the presenter.
$this->addRedraw('content'); // Marks a presenter snippet for redraw (null redraws all snippets).
$this->addFlashMessage('Changes saved.', 'success'); // Adds a presenter flash message.

translate() is a protected helper for formatting messages. Set the public $translator property to use a translator; without one, it returns the message as-is or formats its parameters with vsprintf().

$label = $this->translate('Hello %s', $name);

Form component by name

Returns the form control, or null when the component is not a form control (for example a container):

$form = $this['factory'];
$submitButton = $this->getFormComponent($form, 'submit');
$submitButton->setCaption('Edit');

Form Factory

Drago\Application\UI\Factory creates forms with the translator set (autowired). Extend it for a typed factory of another form class, for example ExtraForms from drago-ex/form:

use Drago\Form\ExtraForms;

/**
 * @extends \Drago\Application\UI\Factory<ExtraForms>
 */
readonly class Factory extends \Drago\Application\UI\Factory
{
	protected function createForm(): ExtraForms
	{
		return new ExtraForms;
	}
}

ExtraTemplate

A base template class with the variables Nette passes to every template ($presenter, $control, $user, $baseUrl, $basePath, $flashes).

Use it in presenter or control PHPDoc:

/**
 * @property-read Drago\Application\UI\ExtraTemplate $template
 */
class Presenter {}

In Latte, declare the template type and the flash messages:

{templateType Drago\Application\UI\ExtraTemplate}
{varType Drago\Application\UI\Flashes[] $flashes}

{include 'path/to/@flash-message.latte', flashes: $flashes}

Flash message alert types

Drago\Application\UI\Alert defines Success, Danger, Warning and Info:

$this->flashMessage('Saved.', Alert::Success);

Toast - Bootstrap and Naja component for flash messages

Each toast is shown once, including toasts added by AJAX snippets, and removed after it hides. Register its script as shown in Assets.

Using toast in a Latte template

{include 'path/to/@toast.latte', flashes: $flashes}

Table widget

@table.latte renders a Bootstrap table. Pass an optional id, caption and themes for the table body and head (primary, secondary, success, danger, warning, info; unknown values use no theme):

{embed 'path/to/@table.latte', tableId: 'users', caption: 'Users', options: [head: 'primary']}
	{block thead}<tr><th>Name</th></tr>{/block}
	{block body}
		<tr n:foreach="$users as $user"><td>{$user->name}</td></tr>
	{/block}
{/embed}

Assets

Add the Composer package as a local npm dependency in package.json (Drago Project installs it by itself):

{
  "type": "module",
  "dependencies": {
    "drago-application": "file:vendor/drago-ex/application"
  }
}

Then run npm install.

Toast

import naja from 'naja';
import { ToastHandler } from 'drago-application';

naja.registerExtension(new ToastHandler());