Template Features
The documentation is constantly evolving and updated alongside the project's progress. Since it is developed in parallel with the code, some sections may temporarily refer to earlier versions of the system-these are gradually adapted to the current state of the application. If you notice any outdated information, please report it or open an Issue / Pull Request.
Documentation
# Template Features
TemplateFeature makes registered view helpers available through the template runtime. The current framework implementation includes helpers for route paths, asset paths, translations, metadata, truncating text, constants, language data, CSRF tokens, request values, enum values, and route state.
# Common helpers
<a href="{{ $this->path('article.show', ['slug' => $slug]) }}">Open</a>
<link rel="stylesheet" href="{{ $this->asset('css/site.css') }}">
<h1>{{ $this->trans('site.title') }}</h1>
<meta name="description" content="{{ $this->meta('meta.description', $meta) }}">
<p>{{ $this->truncate($summary, 120) }}</p>
<input type="hidden" name="csrf_token" value="{{ $this->getCsrfToken() }}">
Other current methods include getSession(), getCookie(), getFlash(), getRequestValue(), getRequestArray(), getEnumValue(), isActive(), hasRoute(), isCurrentRoute(), and replaceContent(). Read their signatures in Dbm\Views\TemplateFeature before using optional arguments. For example, isActive() returns CSS class text for the current named route; it does not return a boolean.
The helper depends on services injected by the configured view provider. Route generation needs a UrlGeneratorInterface; translations need the localization service; CSRF helpers require session support. If a dependency is not configured, a helper may return a fallback or raise a runtime error.
# Flash Messages
Use getFlash() to retrieve a flash message in a template. It returns the available message and its type, or a falsy value when no message is available.
{% $flashMessage = $this->getFlash(); %}
{% if ($flashMessage): %}
<div class="alert {{ \Dbm\Views\Flash\FlashBag::cssClass($flashMessage['type']) }}">
<strong>{{ strtoupper(str_replace('message', '', $flashMessage['type'])) }}:</strong>
<span>{{{ $flashMessage['message'] }}}</span>
</div>
{% endif; %}
FlashBag::cssClass() maps the message type to its CSS class. The default types follow Bootstrap 5 alert conventions:
messageInfo—alert-infomessageWarning—alert-warningmessageDanger—alert-dangermessageSuccess—alert-success
Applications can use the message type to customize presentation in their templates.
Security note: The triple-brace expression in the example renders the message without HTML escaping. Use it only for trusted, application-generated content. Escape messages if they may contain user-controlled data.
For setting messages in controllers, see Controllers and Services.
# Application-specific helpers
Older platform documentation lists helpers such as counterVisits(), linkCanonical(), extractParameter(), htmlCreateSelect(), and htmlLanguage(). These are not methods in the current framework TemplateFeature; use them only if the platform version registers a separate extension providing them.
Keep helpers presentation-focused and avoid putting database access or business decisions in templates. Escape untrusted output and use raw HTML only when it has been deliberately sanitized.