TplEnvironment
in package
Provides a wrapper of Twig\Environment.
Table of Contents
Methods
- __construct() : mixed
- addExtension() : void
- Registers an extension.
- addFilter() : void
- Registers a filter.
- addFunction() : void
- Registers a function.
- addGlobal() : void
- Adds a global variable available in any TplContext instance.
- addTest() : void
- Registers a twig.
- getEnvironment() : Environment
- Get a reference to the underlying Twig Environment.
- isDebug() : bool
- Returns if debug mode is enabled.
- load() : TplContext
- Loads a template and creates a TplContext instance.
- render() : string
- Direct proxy to Environment's render method.
Methods
__construct()
public
__construct(LoaderInterface|string $loader[, CacheInterface|array<string|int, string>|string|null $cache = null ][, string $charset = 'utf-8' ][, bool $debug = false ]) : mixed
Parameters
- $loader : LoaderInterface|string
-
A template loader instance or a path.
- $cache : CacheInterface|array<string|int, string>|string|null = null
-
A caching driver.
- $charset : string = 'utf-8'
-
Character for templates.
- $debug : bool = false
-
Debug mode.
addExtension()
Registers an extension.
public
addExtension(ExtensionInterface $extension) : void
Parameters
- $extension : ExtensionInterface
addFilter()
Registers a filter.
public
addFilter(string $name, callable $body[, array<string, mixed> $options = [] ]) : void
Parameters
- $name : string
-
Name of the filter.
- $body : callable
-
Body of the filter.
- $options : array<string, mixed> = []
-
Options, review the TwigFilter file for the options.
addFunction()
Registers a function.
public
addFunction(string $name, callable $body[, array<string, mixed> $options = [] ]) : void
Parameters
- $name : string
-
Name of the function.
- $body : callable
-
Body of the function.
- $options : array<string, mixed> = []
-
Options, review the TwigFunction file for the options.
addGlobal()
Adds a global variable available in any TplContext instance.
public
addGlobal(string $name, mixed $value) : void
Parameters
- $name : string
-
Name of the variable.
- $value : mixed
-
Content of the variable.
addTest()
Registers a twig.
public
addTest(string $name, callable $body[, array<string, mixed> $options = [] ]) : void
Parameters
- $name : string
-
Name of the twig.
- $body : callable
-
Body of the twig.
- $options : array<string, mixed> = []
-
Options, review the TwigTest file for the options.
getEnvironment()
Get a reference to the underlying Twig Environment.
public
getEnvironment() : Environment
Things that aren't exposed through Index generally have a reason for being "obfuscated" but go wild if you really want to.
Return values
EnvironmentisDebug()
Returns if debug mode is enabled.
public
isDebug() : bool
Return values
boolload()
Loads a template and creates a TplContext instance.
public
load(string $name[, array<string, mixed> $vars = [] ]) : TplContext
Parameters
- $name : string
-
Name or path of the template.
- $vars : array<string, mixed> = []
-
Context local variables to add right away.
Return values
TplContextrender()
Direct proxy to Environment's render method.
public
render(string $name[, array<string, mixed> $vars = [] ]) : string
Parameters
- $name : string
-
Name or path of the template.
- $vars : array<string, mixed> = []
-
Local variables to render the template with.