Twig implements RendererInterface
Twig renderer.
This class is responsible for rendering templates using the Twig templating engine. It initializes Twig with the necessary configurations, loads extensions, and provides methods to render templates, add global variables, and manage translations. It also supports debugging and profiling when in debug mode.
Attributes
- #[Override]
Table of Contents
Interfaces
- RendererInterface
- Renderer interface.
Properties
- $builder : Builder
- Builder object.
- $profile : Profile
- Profile for debugging and profiling.
- $translator : Translator
- Translator instance for translations.
- $twig : Environment
- Twig environment instance.
Methods
- __construct() : mixed
- addGlobal() : void
- Adds a global variable.
- addTransResource() : void
- Adds a translation file.
- getDebugProfile() : Profile|null
- Returns debug profile.
- getTwig() : Environment
- Returns the Twig instance.
- render() : string
- Rendering.
- setLocale() : void
- Set locale (e.g.: 'fr_FR').
- createDateFormatterPrototype() : IntlDateFormatter
- Creates the date formatter prototype used by the Intl extension: it defines the default date and time formats, and exposes the current locale (i.e. the locale of the language being rendered).
- getTranslationsFormatsConfig() : array<string, array{loader: string, ext: string[]}>
Properties
$builder
Builder object.
protected
Builder
$builder
$profile
Profile for debugging and profiling.
private
Profile
$profile
= null$translator
Translator instance for translations.
private
Translator
$translator
= null$twig
Twig environment instance.
private
Environment
$twig
Methods
__construct()
public
__construct(Builder $builder, mixed $templatesPath) : mixed
Parameters
- $builder : Builder
- $templatesPath : mixed
Attributes
- #[Override]
addGlobal()
Adds a global variable.
public
addGlobal(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
Attributes
- #[Override]
addTransResource()
Adds a translation file.
public
addTransResource(string $translationsDir, string $locale[, array<string|int, mixed>|null $formatsConfig = null ]) : void
Parameters
- $translationsDir : string
- $locale : string
- $formatsConfig : array<string|int, mixed>|null = null
Attributes
- #[Override]
getDebugProfile()
Returns debug profile.
public
getDebugProfile() : Profile|null
Return values
Profile|nullgetTwig()
Returns the Twig instance.
public
getTwig() : Environment
Return values
Environmentrender()
Rendering.
public
render(string $template, array<string|int, mixed> $variables) : string
Parameters
- $template : string
- $variables : array<string|int, mixed>
Attributes
- #[Override]
Return values
stringsetLocale()
Set locale (e.g.: 'fr_FR').
public
setLocale(string $locale) : void
Parameters
- $locale : string
Attributes
- #[Override]
createDateFormatterPrototype()
Creates the date formatter prototype used by the Intl extension: it defines the default date and time formats, and exposes the current locale (i.e. the locale of the language being rendered).
private
createDateFormatterPrototype() : IntlDateFormatter
Tags
Return values
IntlDateFormattergetTranslationsFormatsConfig()
private
getTranslationsFormatsConfig() : array<string, array{loader: string, ext: string[]}>