VERSION
VERSION = '2.6.2'
Stores the Twig configuration.
__construct(\Twig_LoaderInterface $loader, array $options = array())
Constructor.
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).
base_template_class: The base template class to use for generated templates (default to Twig_Template).
cache: An absolute path where to store the compiled templates, a Twig_Cache_Interface 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):
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).
\Twig_LoaderInterface | $loader | |
array | $options | An array of options |
getCache(boolean $original = true) : \Twig_CacheInterface|string|false
Gets the current cache implementation.
boolean | $original | Whether to return the original cache option or the real cache instance |
A Twig_CacheInterface implementation, an absolute path to the compiled templates, or false to disable cache
setCache(\Twig_CacheInterface|string|false $cache)
Sets the current cache implementation.
\Twig_CacheInterface|string|false | $cache | A Twig_CacheInterface implementation, an absolute path to the compiled templates, or false to disable cache |
getTemplateClass(string $name, integer|null $index = null) : string
Gets the template class associated with the given string.
The generated template class is based on the following parameters:
string | $name | The name for which to calculate the template class name |
integer|null | $index | The index if it is an embedded template |
The template class name
render(string $name, array $context = array()) : string
Renders a template.
string | $name | The template name |
array | $context | An array of parameters to pass to the template |
When the template cannot be found
When an error occurred during compilation
When an error occurred during rendering
The rendered template
display(string $name, array $context = array())
Displays a template.
string | $name | The template name |
array | $context | An array of parameters to pass to the template |
When the template cannot be found
When an error occurred during compilation
When an error occurred during rendering
load(string|\Twig_TemplateWrapper|\Twig_Template $name) : \Twig_TemplateWrapper
Loads a template.
string|\Twig_TemplateWrapper|\Twig_Template | $name | The template name |
When the template cannot be found
When a previously generated cache is corrupted
When an error occurred during compilation
createTemplate(string $template) : \Twig_Template
Creates a template from source.
This method should not be used as a generic way to load templates.
string | $template | The template name |
When the template cannot be found
When an error occurred during compilation
A template instance representing the given template name
isTemplateFresh(string $name, integer $time) : boolean
Returns true if the template is still fresh.
Besides checking the loader for freshness information, this method also checks if the enabled extensions have not changed.
string | $name | The template name |
integer | $time | The last modification time of the cached template |
true if the template is fresh, false otherwise
resolveTemplate(string|\Twig_Template|\Twig_TemplateWrapper|array $names) : \Twig_Template|\Twig_TemplateWrapper
Tries to load a template consecutively from an array.
Similar to loadTemplate() but it also accepts instances of Twig_Template and Twig_TemplateWrapper, and an array of templates where each is tried to be loaded.
string|\Twig_Template|\Twig_TemplateWrapper|array | $names | A template or an array of templates to try consecutively |
When none of the templates can be found
When an error occurred during compilation
setLexer(\Twig_Lexer $lexer)
\Twig_Lexer | $lexer |
tokenize(\Twig_Source $source) : \Twig_TokenStream
Tokenizes a source code.
\Twig_Source | $source |
When the code is syntactically wrong
setParser(\Twig_Parser $parser)
\Twig_Parser | $parser |
parse(\Twig_TokenStream $stream) : \Twig_Node_Module
Converts a token stream to a node tree.
\Twig_TokenStream | $stream |
When the token stream is syntactically or semantically wrong
setCompiler(\Twig_Compiler $compiler)
\Twig_Compiler | $compiler |
compile(\Twig_Node $node) : string
Compiles a node and returns the PHP code.
\Twig_Node | $node |
The compiled PHP source code
compileSource(\Twig_Source $source) : string
Compiles a template source code.
\Twig_Source | $source |
When there was an error during tokenizing, parsing or compiling
The compiled PHP source code
setLoader(\Twig_LoaderInterface $loader)
\Twig_LoaderInterface | $loader |
getLoader() : \Twig_LoaderInterface
Gets the Loader instance.
addRuntimeLoader(\Twig_RuntimeLoaderInterface $loader)
Adds a runtime loader.
\Twig_RuntimeLoaderInterface | $loader |
getExtension(string $class) : \Twig_ExtensionInterface
Gets an extension by class name.
string | $class | The extension class name |
addExtension(\Twig_ExtensionInterface $extension)
\Twig_ExtensionInterface | $extension |
getExtensions() : array<mixed,\Twig_ExtensionInterface>
Returns all registered extensions.
An array of extensions (keys are for internal usage only and should not be relied on)
addTokenParser(\Twig_TokenParserInterface $parser)
\Twig_TokenParserInterface | $parser |
addNodeVisitor(\Twig_NodeVisitorInterface $visitor)
\Twig_NodeVisitorInterface | $visitor |
addFilter(\Twig_Filter $filter)
\Twig_Filter | $filter |
addTest(\Twig_Test $test)
Registers a Test.
\Twig_Test | $test | A Twig_Test instance |
addFunction(\Twig_Function $function)
\Twig_Function | $function |