TwigTemplateEngine
extends TemplateEngine
in package
Base template engine class to be extended.
Table of Contents
Properties
- $_twig : Environment
- $_variables : array<string|int, mixed>
Methods
- __construct() : mixed
- addVariable() : void
- Register a template variable.
- addVariables() : void
- Register several template variables.
- clearCache() : void
- Clear template cache directory.
- fetch() : string
- Fetch a generated template file using the set template engine.
- getVariable() : mixed
- Get a template variable.
- getVariables() : array<string|int, mixed>
- Get all template variables.
- render() : void
- Render a template file using the set template engine.
Properties
$_twig
private
Environment
$_twig
$_variables
private
array<string|int, mixed>
$_variables
Methods
__construct()
public
__construct(string $dir) : mixed
Parameters
- $dir : string
-
Path to template directory
addVariable()
Register a template variable.
public
addVariable(string $key, mixed $value) : void
TODO: mixed type for $value
Parameters
- $key : string
- $value : mixed
addVariables()
Register several template variables.
public
addVariables(array<string|int, mixed> $variables) : void
Parameters
- $variables : array<string|int, mixed>
clearCache()
Clear template cache directory.
public
clearCache() : void
fetch()
Fetch a generated template file using the set template engine.
public
fetch(string $templateFile) : string
Parameters
- $templateFile : string
-
Path to template file to render.
Return values
string —HTML to render
getVariable()
Get a template variable.
public
getVariable(string $key) : mixed
Parameters
- $key : string
getVariables()
Get all template variables.
public
getVariables() : array<string|int, mixed>
Return values
array<string|int, mixed>render()
Render a template file using the set template engine.
public
render(string $templateFile) : void
Parameters
- $templateFile : string
-
Path to template file to render.