TwigLoader
in package
implements
TwigLoaderInterface
This is the TwigLoader class.
This class facilitates the creation and initialization of the Twig Environment.
Tags
Interfaces, Classes and Traits
- TwigLoaderInterface
- This is the TwigLoaderInterface.
Table of Contents
__construct() | Constructor. Creates the TwigLoader and initializes it with the given Theme. | : mixed |
---|---|---|
addFunction() | This method adds the given function to the Twig Environment. | : void |
getTwigEnvironment() | This method returns the Twig Environment. | : Environment |
load() | This method creates and initializes the Twig Environment. | : void |
render() | This method uses Twig Environment to render the page and returns the renderization. | : string |
Methods
__construct()
Constructor. Creates the TwigLoader and initializes it with the given Theme.
public
__construct(Theme $theme[, string $themeName = null ]) : mixed
Parameters
- $theme : Theme
- $themeName : string = null
Return values
mixed —addFunction()
This method adds the given function to the Twig Environment.
public
addFunction( $fn) : void
Parameters
Return values
void —getTwigEnvironment()
This method returns the Twig Environment.
public
getTwigEnvironment() : Environment
Return values
Environment —load()
This method creates and initializes the Twig Environment.
public
load([array<string|int, mixed> $data = [] ], int $autoescape[, bool $loadCore = true ]) : void
For the initialization it takes into account the Theme specified in the TwigLoader creation and all the data given by parameters to this method.
Parameters
- $data : array<string|int, mixed> = []
-
-> All the needed data to be accesible from Twig templates.
- $autoescape : int
-
-> @See TwigAutoescape::AUTOESCAPE_*. https://twig.symfony.com/doc/2.x/tags/autoescape.html
- $loadCore : bool = true
-
-> To indicate if it is required to load the Twig Core Macros functionality.
Return values
void —render()
This method uses Twig Environment to render the page and returns the renderization.
public
render([string $content = null ][, string $layout = null ][, string $version = null ][, string $format = 'html' ]) : string
The renderization is based on the Theme provided in the TwigLoader creation, the data provided with the load method and the format specified by parameter(by default html).
Parameters
- $content : string = null
-
-> If different to null, it overrides the theme content to load in Twig
- $layout : string = null
-
-> If different to null, it overrides the theme layout to load in Twig
- $version : string = null
-
-> If different to null, it overrides the theme version to load in Twig
- $format : string = 'html'
-
-> Default value: 'html'. Set the format to mark the name of the layout. For example, with "json" value, Twig renderization will load default.json.twig