HumHub Documentation (unofficial)

Environment
in package

Stores the Twig configuration and renders templates.

Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

Constants

EXTRA_VERSION  = ''
MAJOR_VERSION  = 3
MINOR_VERSION  = 10
RELEASE_VERSION  = 3
VERSION  = '3.10.3'
VERSION_ID  = 301003

Properties

$autoReload  : mixed
$cache  : mixed
$charset  : mixed
$compiler  : mixed
$debug  : mixed
$defaultRuntimeLoader  : mixed
$extensionSet  : mixed
$globals  : array<string, mixed>
$lexer  : mixed
$loadedTemplates  : mixed
$loader  : mixed
$optionsHash  : mixed
$originalCache  : mixed
$parser  : mixed
$resolvedGlobals  : mixed
$runtimeLoaders  : mixed
$runtimes  : mixed
$strictVariables  : mixed
$templateClassPrefix  : mixed
$useYield  : bool

Methods

__construct()  : mixed
Constructor.
addExtension()  : mixed
addFilter()  : mixed
addFunction()  : mixed
addGlobal()  : mixed
Registers a Global.
addNodeVisitor()  : mixed
addRuntimeLoader()  : mixed
addTest()  : mixed
addTokenParser()  : mixed
compile()  : string
Compiles a node and returns the PHP code.
compileSource()  : string
Compiles a template source code.
createTemplate()  : TemplateWrapper
Creates a template from source.
disableAutoReload()  : mixed
Disables the auto_reload option.
disableDebug()  : mixed
Disables debugging mode.
disableStrictVariables()  : mixed
Disables the strict_variables option.
display()  : void
Displays a template.
enableAutoReload()  : mixed
Enables the auto_reload option.
enableDebug()  : mixed
Enables debugging mode.
enableStrictVariables()  : mixed
Enables the strict_variables option.
getCache()  : CacheInterface|string|false
Gets the current cache implementation.
getCharset()  : string
getExtension()  : TExtension
getExtensions()  : array<string|int, ExtensionInterface>
getLoader()  : LoaderInterface
getRuntime()  : TRuntime
Returns the runtime implementation of a Twig element (filter/function/tag/test).
hasExtension()  : bool
isAutoReload()  : bool
Checks if the auto_reload option is enabled.
isDebug()  : bool
Checks if debug mode is enabled.
isStrictVariables()  : bool
Checks if the strict_variables option is enabled.
isTemplateFresh()  : bool
Returns true if the template is still fresh.
load()  : TemplateWrapper
Loads a template.
mergeGlobals()  : array<string|int, mixed>
parse()  : ModuleNode
Converts a token stream to a node tree.
registerUndefinedFilterCallback()  : void
registerUndefinedFunctionCallback()  : void
registerUndefinedTokenParserCallback()  : void
render()  : string
Renders a template.
resolveTemplate()  : TemplateWrapper
Tries to load a template consecutively from an array.
setCache()  : mixed
Sets the current cache implementation.
setCharset()  : mixed
setCompiler()  : mixed
setExtensions()  : mixed
setLexer()  : mixed
setLoader()  : mixed
setParser()  : mixed
tokenize()  : TokenStream
updateOptionsHash()  : void

Constants

Properties

$defaultRuntimeLoader

private mixed $defaultRuntimeLoader

$templateClassPrefix

private mixed $templateClassPrefix = '__TwigTemplate_'

Methods

__construct()

Constructor.

public __construct(LoaderInterface $loader[, mixed $options = [] ]) : mixed

Available options:

  • debug: When set to true, it automatically set "auto_reload" to true as well (default to false).

  • charset: The charset used by the templates (default to UTF-8).

  • cache: An absolute path where to store the compiled templates, a \Twig\Cache\CacheInterface implementation, or false to disable compilation cache (default).

  • auto_reload: Whether to reload the template if the original source changed. If you don't provide the auto_reload option, it will be determined automatically based on the debug value.

  • strict_variables: Whether to ignore invalid variables in templates (default to false).

  • autoescape: Whether to enable auto-escaping (default to html): * false: disable auto-escaping * html, js: set the autoescaping to one of the supported strategies * name: set the autoescaping strategy based on the template name extension * PHP callback: a PHP callback that returns an escaping strategy based on the template "name"

  • optimizations: A flag that indicates which optimizations to apply (default to -1 which means that all optimizations are enabled; set it to 0 to disable).

  • use_yield: Enable templates to exclusively use "yield" instead of "echo" (default to "false", but switch it to "true" when possible as this will be the only supported mode in Twig 4.0)

Parameters
$loader : LoaderInterface
$options : mixed = []

addGlobal()

Registers a Global.

public addGlobal(string $name, mixed $value) : mixed

New globals can be added before compiling or rendering a template; but after, you can only update existing globals.

Parameters
$name : string
$value : mixed

The global value

compile()

Compiles a node and returns the PHP code.

public compile(Node $node) : string
Parameters
$node : Node
Return values
string

compileSource()

Compiles a template source code.

public compileSource(Source $source) : string
Parameters
$source : Source
Tags
throws
SyntaxError

When there was an error during tokenizing, parsing or compiling

Return values
string

createTemplate()

Creates a template from source.

public createTemplate(string $template[, string|null $name = null ]) : TemplateWrapper

This method should not be used as a generic way to load templates.

Parameters
$template : string

The template source

$name : string|null = null

An optional name of the template to be used in error messages

Tags
throws
LoaderError

When the template cannot be found

throws
SyntaxError

When an error occurred during compilation

Return values
TemplateWrapper

disableAutoReload()

Disables the auto_reload option.

public disableAutoReload() : mixed

disableDebug()

Disables debugging mode.

public disableDebug() : mixed

disableStrictVariables()

Disables the strict_variables option.

public disableStrictVariables() : mixed

display()

Displays a template.

public display(string|TemplateWrapper $name[, array<string|int, mixed> $context = [] ]) : void
Parameters
$name : string|TemplateWrapper

The template name

$context : array<string|int, mixed> = []
Tags
throws
LoaderError

When the template cannot be found

throws
SyntaxError

When an error occurred during compilation

throws
RuntimeError

When an error occurred during rendering

enableAutoReload()

Enables the auto_reload option.

public enableAutoReload() : mixed

enableDebug()

Enables debugging mode.

public enableDebug() : mixed

enableStrictVariables()

Enables the strict_variables option.

public enableStrictVariables() : mixed

getCache()

Gets the current cache implementation.

public getCache([bool $original = true ]) : CacheInterface|string|false
Parameters
$original : bool = true

Whether to return the original cache option or the real cache instance

Return values
CacheInterface|string|false

A Twig\Cache\CacheInterface implementation, an absolute path to the compiled templates, or false to disable cache

getCharset()

public getCharset() : string
Return values
string

getExtension()

public getExtension(TExtension> $class) : TExtension
Parameters
$class : TExtension>
Tags
template

TExtension of ExtensionInterface

Return values
TExtension

getRuntime()

Returns the runtime implementation of a Twig element (filter/function/tag/test).

public getRuntime(TRuntime> $class) : TRuntime
Parameters
$class : TRuntime>

A runtime class name

Tags
template

TRuntime of object

throws
RuntimeError

When the template cannot be found

Return values
TRuntime

The runtime implementation

hasExtension()

public hasExtension(string $class) : bool
Parameters
$class : string
Return values
bool

isAutoReload()

Checks if the auto_reload option is enabled.

public isAutoReload() : bool
Return values
bool

true if auto_reload is enabled, false otherwise

isDebug()

Checks if debug mode is enabled.

public isDebug() : bool
Return values
bool

true if debug mode is enabled, false otherwise

isStrictVariables()

Checks if the strict_variables option is enabled.

public isStrictVariables() : bool
Return values
bool

true if strict_variables is enabled, false otherwise

isTemplateFresh()

Returns true if the template is still fresh.

public isTemplateFresh(string $name, int $time) : bool

Besides checking the loader for freshness information, this method also checks if the enabled extensions have not changed.

Parameters
$name : string
$time : int

The last modification time of the cached template

Return values
bool

mergeGlobals()

public mergeGlobals(array<string|int, mixed> $context) : array<string|int, mixed>
Parameters
$context : array<string|int, mixed>
Return values
array<string|int, mixed>

registerUndefinedFilterCallback()

public registerUndefinedFilterCallback(callable $callable) : void
Parameters
$callable : callable

registerUndefinedFunctionCallback()

public registerUndefinedFunctionCallback(callable $callable) : void
Parameters
$callable : callable

registerUndefinedTokenParserCallback()

public registerUndefinedTokenParserCallback(callable $callable) : void
Parameters
$callable : callable

render()

Renders a template.

public render(string|TemplateWrapper $name[, array<string|int, mixed> $context = [] ]) : string
Parameters
$name : string|TemplateWrapper

The template name

$context : array<string|int, mixed> = []
Tags
throws
LoaderError

When the template cannot be found

throws
SyntaxError

When an error occurred during compilation

throws
RuntimeError

When an error occurred during rendering

Return values
string

resolveTemplate()

Tries to load a template consecutively from an array.

public resolveTemplate(string|TemplateWrapper|array<string|int, string|TemplateWrapper$names) : TemplateWrapper

Similar to load() but it also accepts instances of \Twig\TemplateWrapper and an array of templates where each is tried to be loaded.

Parameters
$names : string|TemplateWrapper|array<string|int, string|TemplateWrapper>

A template or an array of templates to try consecutively

Tags
throws
LoaderError

When none of the templates can be found

throws
SyntaxError

When an error occurred during compilation

Return values
TemplateWrapper

setCache()

Sets the current cache implementation.

public setCache(CacheInterface|string|false $cache) : mixed
Parameters
$cache : CacheInterface|string|false

A Twig\Cache\CacheInterface implementation, an absolute path to the compiled templates, or false to disable cache

setCharset()

public setCharset(string $charset) : mixed
Parameters
$charset : string

updateOptionsHash()

private updateOptionsHash() : void

        
On this page

Search results