ViewHelpers
final class ViewHelpers (View source)
Exposes URL, localization, image, and session-backed CSRF operations to one request's views.
Methods
Binds app-scoped utilities and the current request's CSRF helper into one template API.
Returns a root-relative asset URL without requiring a canonical application origin.
Renders an image reference through the optional image integration.
Generates a URL for a named route.
Generates a locale-aware URL for a named route.
Renders an escaped hidden field containing a token from the current session.
Returns a named CSRF token from the current session.
Translates one message with scalar replacements.
Returns the active runtime locale or a configured or caller-provided fallback.
Returns one complete translation group for a locale.
Returns every translation group for a locale.
Details
__construct
__construct(UrlGenerator $urlGenerator, CsrfViewHelper $csrf, TranslatorInterface $translator, LocalizationConfig $config, ImageViewHelper|null $images = null)
Binds app-scoped utilities and the current request's CSRF helper into one template API.
asset
string
asset(string $path)
Returns a root-relative asset URL without requiring a canonical application origin.
image
string
image(ImageReference|null $reference, ImageViewOptions|null $options = null)
Renders an image reference through the optional image integration.
url
string
url(string $route, array $params = [])
Generates a URL for a named route.
localizedUrl
string
localizedUrl(string $route, array $params = [], string|null $locale = null)
Generates a locale-aware URL for a named route.
csrfField
string
csrfField(string $name = 'default')
Renders an escaped hidden field containing a token from the current session.
csrfToken
string
csrfToken(string $name = 'default')
Returns a named CSRF token from the current session.
lang
string
lang(string $key, array $replacements = [], string|null $locale = null)
Translates one message with scalar replacements.
currentLocale
string
currentLocale(string $default = 'en')
Returns the active runtime locale or a configured or caller-provided fallback.
langGroup
array
langGroup(string $group, string|null $locale = null)
Returns one complete translation group for a locale.
langAll
array
langAll(string|null $locale = null)
Returns every translation group for a locale.