Webiik\View\View
Template engine incorporation. Template rendering.
It is defined in private/config/container/services.php
. By default, the service View is defined to utilize Twig template engine. It reads templates from private/frontend
and writes cache to private/tmp/view
. Also, it extends Twig with the set of additional template functions and variables:
getRoute(): string
getRoute() returns current route name.
{{ getRoute() }}
getURL(string $route, array $parameters = [], string $lang = WEBIIK_LANG): string
getURL() returns URL by route name.
{{ getURL('home') }}
_t(string $key, array|bool|null $context = null): string|array
_t() returns route and language related translations by key.
{{ _t('message', {'name': 'Tom'}) }}
getCSS(string $route): string
getCSS() returns HTML tags with route related CSS.
{{ getCSS(getRoute()) }}
getJS(string $route, bool $beforeDOM): string
getJS() returns HTML tags with route related JS.
{{ getJS(getRoute()) }}
reactComponent(string $name, array $props, array $options = []): string
reactComponent() returns HTML tags with React component.
{{ reactComponent("Meow", []) }}
{{ WEBIIK_DEBUG }}
{{ WEBIIK_LANG }}
{{ WEBIIK_BASE_URI }}
{{ WEBIIK_BASE_URL }}
{{ WEBIIK_BASE_PATH }}
Read more about the meaning of these variables here.
The View component allows you to easily change the template engine. So if you don’t want to use Twig, just change the definition of the service View.
Please, follow these rules:
private/frontend
private/tmp/view
In route controller.
Read documentation to learn more about View component.