Twig
in package
Class Twig
Table of Contents
Properties
- $plugins_hooked_dashboard_widgets_main : array<string|int, mixed>
- $plugins_hooked_dashboard_widgets_top : array<string|int, mixed>
- $plugins_hooked_nav : array<string|int, mixed>
- $plugins_quick_tray : array<string|int, mixed>
- $template : string
- $twig : Environment
- $twig_paths : array<string|int, mixed>
- $twig_vars : array<string|int, mixed>
- $autoescape : bool
- $grav : Grav
- $loader : FilesystemLoader
- $loaderArray : ArrayLoader
- $profile : Profile
Methods
- __construct() : mixed
- Constructor
- addPath() : mixed
- Wraps the FilesystemLoader addPath method (should be used only in `onTwigLoader()` event
- getPageTwigTemplate() : string
- init() : $this
- Twig initialization that sets the twig loader chain, then the environment, then extensions and also the base set of twig vars
- loader() : FilesystemLoader
- prependPath() : mixed
- Wraps the FilesystemLoader prependPath method (should be used only in `onTwigLoader()` event
- processPage() : string
- Twig process that renders a page item. It supports two variations: 1) Handles modular pages by rendering a specific page based on its modular twig template 2) Renders individual page items for twig processing before the site rendering
- processSite() : string
- Twig process that renders the site layout. This is the main twig process that renders the overall page and handles all the layout for the site display.
- processString() : string
- Process a Twig template directly by using a Twig string and optional array of variables
- processTemplate() : string
- Process a Twig template directly by using a template name and optional array of variables
- profile() : Profile
- setAutoescape() : void
- Overrides the autoescape setting
- setTemplate() : mixed
- Adds or overrides a template.
- template() : string
- Simple helper method to get the twig template if it has already been set, else return the one being passed in NOTE: Modular pages that are injected should not use this pre-set template as it's usually set at the page level
- twig() : Environment
Properties
$plugins_hooked_dashboard_widgets_main
public
array<string|int, mixed>
$plugins_hooked_dashboard_widgets_main
= []
$plugins_hooked_dashboard_widgets_top
public
array<string|int, mixed>
$plugins_hooked_dashboard_widgets_top
= []
$plugins_hooked_nav
public
array<string|int, mixed>
$plugins_hooked_nav
= []
$plugins_quick_tray
public
array<string|int, mixed>
$plugins_quick_tray
= []
$template
public
string
$template
$twig
public
Environment
$twig
$twig_paths
public
array<string|int, mixed>
$twig_paths
$twig_vars
public
array<string|int, mixed>
$twig_vars
= []
$autoescape
protected
bool
$autoescape
$grav
protected
Grav
$grav
$loader
protected
FilesystemLoader
$loader
$loaderArray
protected
ArrayLoader
$loaderArray
$profile
protected
Profile
$profile
Methods
__construct()
Constructor
public
__construct(Grav $grav) : mixed
Parameters
- $grav : Grav
addPath()
Wraps the FilesystemLoader addPath method (should be used only in `onTwigLoader()` event
public
addPath(string $template_path[, string $namespace = '__main__' ]) : mixed
Parameters
- $template_path : string
- $namespace : string = '__main__'
Tags
getPageTwigTemplate()
public
getPageTwigTemplate(PageInterface $page[, string|null &$format = null ]) : string
Parameters
- $page : PageInterface
- $format : string|null = null
Return values
stringinit()
Twig initialization that sets the twig loader chain, then the environment, then extensions and also the base set of twig vars
public
init() : $this
Return values
$thisloader()
public
loader() : FilesystemLoader
Return values
FilesystemLoaderprependPath()
Wraps the FilesystemLoader prependPath method (should be used only in `onTwigLoader()` event
public
prependPath(string $template_path[, string $namespace = '__main__' ]) : mixed
Parameters
- $template_path : string
- $namespace : string = '__main__'
Tags
processPage()
Twig process that renders a page item. It supports two variations: 1) Handles modular pages by rendering a specific page based on its modular twig template 2) Renders individual page items for twig processing before the site rendering
public
processPage(PageInterface $item[, string|null $content = null ]) : string
Parameters
- $item : PageInterface
-
The page item to render
- $content : string|null = null
-
Optional content override
Return values
string —The rendered output
processSite()
Twig process that renders the site layout. This is the main twig process that renders the overall page and handles all the layout for the site display.
public
processSite([string|null $format = null ][, array<string|int, mixed> $vars = [] ]) : string
Parameters
- $format : string|null = null
-
Output format (defaults to HTML).
- $vars : array<string|int, mixed> = []
Tags
Return values
string —the rendered output
processString()
Process a Twig template directly by using a Twig string and optional array of variables
public
processString(string $string[, array<string|int, mixed> $vars = [] ]) : string
Parameters
- $string : string
-
string to render.
- $vars : array<string|int, mixed> = []
-
Optional variables
Return values
stringprocessTemplate()
Process a Twig template directly by using a template name and optional array of variables
public
processTemplate(string $template[, array<string|int, mixed> $vars = [] ]) : string
Parameters
- $template : string
-
template to render with
- $vars : array<string|int, mixed> = []
-
Optional variables
Return values
stringprofile()
public
profile() : Profile
Return values
ProfilesetAutoescape()
Overrides the autoescape setting
public
setAutoescape(bool $state) : void
Auto-escape should always be turned on to protect against XSS issues (can be disabled per template file).
Parameters
- $state : bool
setTemplate()
Adds or overrides a template.
public
setTemplate(string $name, string $template) : mixed
Parameters
- $name : string
-
The template name
- $template : string
-
The template source
template()
Simple helper method to get the twig template if it has already been set, else return the one being passed in NOTE: Modular pages that are injected should not use this pre-set template as it's usually set at the page level
public
template(string $template) : string
Parameters
- $template : string
-
the template name
Return values
string —the template name
twig()
public
twig() : Environment