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.
Table of Contents
Interfaces
- RendererInterface
- Renderer interface.
Properties
- $builder : Builder
- $profile : Profile
- $translator : Translator
- $twig : Environment
- $profile : Profile
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').
Properties
$builder
private
Builder
$builder
$profile
private
Profile
$profile
= null
$translator
private
Translator
$translator
= null
$twig
private
Environment
$twig
Methods
__construct()
public
__construct(Builder $builder, mixed $templatesPath) : mixed
Parameters
- $builder : Builder
- $templatesPath : mixed
addGlobal()
Adds a global variable.
public
addGlobal(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
addTransResource()
Adds a translation file.
public
addTransResource(string $translationsDir, string $locale) : void
Parameters
- $translationsDir : string
- $locale : string
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>
Return values
stringsetLocale()
Set locale (e.g.: 'fr_FR').
public
setLocale(string $locale) : void
Parameters
- $locale : string