View

Service Name in Container

Webiik\View\View

Purpose

Template engine incorporation. Template rendering.

Definition

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

getRoute(): string

getRoute() returns current route name.


{{ getRoute() }}

getURL

getURL(string $route, array $parameters = [], string $lang = WEBIIK_LANG): string

getURL() returns URL by route name.


{{ getURL('home') }}

_t

_t(string $key, array|bool|null $context = null): string|array

_t() returns route and language related translations by key.


{{ _t('message', {'name': 'Tom'}) }}

getCSS

getCSS(string $route): string

getCSS() returns HTML tags with route related CSS.


{{ getCSS(getRoute()) }}

getJS

getJS(string $route, bool $beforeDOM): string

getJS() returns HTML tags with route related JS.


{{ getJS(getRoute()) }}

reactComponent

reactComponent(string $name, array $props, array $options = []): string

reactComponent() returns HTML tags with React component.


{{ reactComponent("Meow", []) }}

Variables


{{ WEBIIK_DEBUG }}
{{ WEBIIK_LANG }}
{{ WEBIIK_BASE_URI }}
{{ WEBIIK_BASE_URL }}
{{ WEBIIK_BASE_PATH }}

Read more about the meaning of these variables here.

Changing the template engine

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:

Usual Usage

In route controller.

Documentation

Read documentation to learn more about View component.