Application Configuration

Overview of configuration options for Nette Application.

Application

application:
	# show the "Nette Application" panel in Tracy BlueScreen?
	debugger: ...           # (bool) defaults to true

	# will the error-presenter be called on error?
	# effective only in development mode
	catchExceptions: ...    # (bool) defaults to true

	# name of the error-presenter
	errorPresenter: Error   # (string|array) defaults to 'Nette:Error'

	# defines aliases for presenters and actions
	aliases: ...

	# defines the rules for translating the presenter name to a class
	mapping: ...

	# suppress warnings for invalid links?
	# effective only in development mode
	silentLinks: ...        # (bool) defaults to false

Since nette/application version 3.2, it is possible to define a pair of error presenters:

application:
	errorPresenter:
		4xx: Error4xx   # for Nette\Application\BadRequestException
		5xx: Error5xx   # for other exceptions

The silentLinks option determines how Nette behaves in development mode when link generation fails (for example, because the presenter does not exist, etc.). The default value false means that Nette triggers an E_USER_WARNING error. Setting it to true suppresses this error message. In a production environment, E_USER_WARNING is always triggered. This behavior can also be influenced by setting the presenter variable $invalidLinkMode.

Aliases simplify referencing frequently used presenters.

The mapping defines the rules by which the class name is derived from the presenter name.

Automatic Registration of Presenters

Nette automatically adds presenters as services to the DI container, which significantly speeds up their creation. How Nette locates presenters can be configured:

application:
	# look for presenters in Composer class map?
	scanComposer: ...      # (bool) defaults to true

	# a mask that the class and file name must match
	scanFilter: ...        # (string) defaults to '*Presenter'

	# in which directories to look for presenters?
	scanDirs:              # (string[]|false) defaults to '%appDir%'
		- %vendorDir%/mymodule

The directories listed in scanDirs do not override the default value %appDir%, but complement it, so scanDirs will contain both paths %appDir% and %vendorDir%/mymodule. If we want to omit the default directory, we use an exclamation mark:

application:
	scanDirs!:
		- %vendorDir%/mymodule

Directory scanning can be turned off by setting the value to false. We do not recommend completely suppressing the automatic addition of presenters, as this will reduce application performance.

Latte Templates

This setting globally affects the behavior of Latte in components and presenters.

latte:
	# show the Latte panel in the Tracy Bar for the main template (true) or for all components (all)?
	debugger: ...        # (true|false|'all') defaults to true

	# generate templates with declare(strict_types=1) header
	strictTypes: ...     # (bool) defaults to false

	# enable [strict parser mode |latte:develop#strict mode]
	strictParsing: ...   # (bool) default is false

	# enable [checking of generated code |latte:develop#Checking Generated Code]
	phpLinter: ...       # (string) default is null

	# set the locale
	locale: cs_CZ        # (string) default is null

	# class of the $this->template object
	templateClass: App\MyTemplateClass # defaults to Nette\Bridges\ApplicationLatte\DefaultTemplate

If you are using Latte version 3, you can add new extensions using:

latte:
	extensions:
		- Latte\Essential\TranslatorExtension(@Nette\Localization\Translator)

If you are using Latte version 2, you can register new tags either by specifying the class name or by referencing a service. By default, the install() method is called, but this can be changed by specifying the name of another method:

latte:
	# registration of custom Latte tags
	macros:
		- App\MyLatteMacros::register         # static method, classname or callable
		- @App\MyLatteMacrosFactory           # service with install() method
		- @App\MyLatteMacrosFactory::register # service with register() method

services:
	- App\MyLatteMacrosFactory

Routing

Basic settings:

routing:
	# show the routing panel in Tracy Bar?
	debugger: ...   # (bool) defaults to true

	# serialize the router into the DI container
	cache: ...      # (bool) defaults to false

Routing is usually defined in the RouterFactory class. Alternatively, routes can also be defined in the configuration using mask: action pairs, but this method does not offer much flexibility:

routing:
	routes:
		'detail/<id>': Admin:Home:default
		'<presenter>/<action>': Front:Home:default

Constants

Creating PHP constants.

constants:
	Foobar: 'baz'

The Foobar constant will be created after the application starts.

Constants should not serve as globally available variables. To pass values to objects, use dependency injection.

PHP

Setting PHP directives. An overview of all directives can be found at php.net.

php:
	date.timezone: Europe/Prague

DI Services

These services are added to the DI container:

Name Type Description
application.application Nette\Application\Application the application runner
application.linkGenerator Nette\Application\LinkGenerator LinkGenerator
application.presenterFactory Nette\Application\PresenterFactory presenter factory
application.### Nette\Application\UI\Presenter individual presenters
latte.latteFactory Nette\Bridges\ApplicationLatte\LatteFactory factory for Latte\Engine object
latte.templateFactory Nette\Application\UI\TemplateFactory factory for $this->template
version: 4.0 3.x 2.x