class Twig_Environment
Stores the Twig configuration.
Constants
| VERSION |
|
Methods
|
__construct(Twig_LoaderInterface $loader = null, array $options = array())
Constructor. |
||
| string |
getBaseTemplateClass()
Gets the base template class for compiled templates. |
|
|
setBaseTemplateClass(string $class)
Sets the base template class for compiled templates. |
||
|
enableDebug()
Enables debugging mode. |
||
|
disableDebug()
Disables debugging mode. |
||
| Boolean |
isDebug()
Checks if debug mode is enabled. |
|
|
enableAutoReload()
Enables the auto_reload option. |
||
|
disableAutoReload()
Disables the auto_reload option. |
||
| Boolean |
isAutoReload()
Checks if the auto_reload option is enabled. |
|
|
enableStrictVariables()
Enables the strict_variables option. |
||
|
disableStrictVariables()
Disables the strict_variables option. |
||
| Boolean |
isStrictVariables()
Checks if the strict_variables option is enabled. |
|
| string|false |
getCache()
Gets the cache directory or false if cache is disabled. |
|
|
setCache(string|false $cache)
Sets the cache directory or false if cache is disabled. |
||
| string |
getCacheFilename(string $name)
Gets the cache filename for a given template. |
|
| string |
getTemplateClass(string $name, integer $index = null)
Gets the template class associated with the given string. |
|
| string |
getTemplateClassPrefix()
Gets the template class prefix. |
|
| string |
render(string $name, array $context = array())
Renders a template. |
|
|
display(string $name, array $context = array())
Displays a template. |
||
| Twig_TemplateInterface |
loadTemplate(string $name, integer $index = null)
Loads a template by name. |
|
| Boolean |
isTemplateFresh(string $name, timestamp $time)
Returns true if the template is still fresh. |
|
|
resolveTemplate($names)
|
||
|
clearTemplateCache()
Clears the internal template cache. |
||
|
clearCacheFiles()
Clears the template cache files on the filesystem. |
||
| Twig_LexerInterface |
getLexer()
Gets the Lexer instance. |
|
|
setLexer(Twig_LexerInterface $lexer)
Sets the Lexer instance. |
||
| Twig_TokenStream |
tokenize(string $source, string $name = null)
Tokenizes a source code. |
|
| Twig_ParserInterface |
getParser()
Gets the Parser instance. |
|
|
setParser(Twig_ParserInterface $parser)
Sets the Parser instance. |
||
| Twig_Node_Module |
parse(Twig_TokenStream $tokens)
Parses a token stream. |
|
| Twig_CompilerInterface |
getCompiler()
Gets the Compiler instance. |
|
|
setCompiler(Twig_CompilerInterface $compiler)
Sets the Compiler instance. |
||
| string |
compile(Twig_NodeInterface $node)
Compiles a Node. |
|
| string |
compileSource(string $source, string $name = null)
Compiles a template source code. |
|
|
setLoader(Twig_LoaderInterface $loader)
Sets the Loader instance. |
||
| Twig_LoaderInterface |
getLoader()
Gets the Loader instance. |
|
|
setCharset(string $charset)
Sets the default template charset. |
||
| string |
getCharset()
Gets the default template charset. |
|
|
initRuntime()
Initializes the runtime environment. |
||
| Boolean |
hasExtension(string $name)
Returns true if the given extension is registered. |
|
| Twig_ExtensionInterface |
getExtension(string $name)
Gets an extension by name. |
|
|
addExtension(Twig_ExtensionInterface $extension)
Registers an extension. |
||
|
removeExtension(string $name)
Removes an extension by name. |
||
|
setExtensions(array $extensions)
Registers an array of extensions. |
||
| array |
getExtensions()
Returns all registered extensions. |
|
|
addTokenParser(Twig_TokenParserInterface $parser)
Registers a Token Parser. |
||
| Twig_TokenParserBrokerInterface |
getTokenParsers()
Gets the registered Token Parsers. |
|
| Twig_TokenParserInterface[] |
getTags()
Gets registered tags. |
|
|
addNodeVisitor(Twig_NodeVisitorInterface $visitor)
Registers a Node Visitor. |
||
| Twig_NodeVisitorInterface[] |
getNodeVisitors()
Gets the registered Node Visitors. |
|
|
addFilter(string|Twig_SimpleFilter $name, Twig_FilterInterface|Twig_SimpleFilter $filter = null)
Registers a Filter. |
||
| Twig_Filter|false |
getFilter(string $name)
Get a filter by name. |
|
|
registerUndefinedFilterCallback($callable)
|
||
| Twig_FilterInterface[] |
getFilters()
Gets the registered Filters. |
|
|
addTest(string|Twig_SimpleTest $name, Twig_TestInterface|Twig_SimpleTest $test = null)
Registers a Test. |
||
| Twig_TestInterface[] |
getTests()
Gets the registered Tests. |
|
| Twig_Test|false |
getTest(string $name)
Gets a test by name. |
|
|
addFunction(string|Twig_SimpleFunction $name, Twig_FunctionInterface|Twig_SimpleFunction $function = null)
Registers a Function. |
||
| Twig_Function|false |
getFunction(string $name)
Get a function by name. |
|
|
registerUndefinedFunctionCallback($callable)
|
||
| Twig_FunctionInterface[] |
getFunctions()
Gets registered functions. |
|
|
addGlobal(string $name, mixed $value)
Registers a Global. |
||
| array |
getGlobals()
Gets the registered Globals. |
|
| array |
mergeGlobals(array $context)
Merges a context with the defined globals. |
|
| array |
getUnaryOperators()
Gets the registered unary Operators. |
|
| array |
getBinaryOperators()
Gets the registered binary Operators. |
|
|
computeAlternatives($name, $items)
|
Details
at line 84
public
__construct(Twig_LoaderInterface $loader = null, 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).
basetemplateclass: The base template class to use for generated templates (default to Twig_Template).
cache: An absolute path where to store the compiled templates, or false to disable compilation cache (default).
autoreload: Whether to reload the template is the original source changed. If you don't provide the autoreload option, it will be determined automatically base 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 * true: equivalent to html * html, js: set the autoescaping to one of the supported strategies * PHP callback: a PHP callback that returns an escaping strategy based on the template "filename"
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).
at line 123
public string
getBaseTemplateClass()
Gets the base template class for compiled templates.
at line 133
public
setBaseTemplateClass(string $class)
Sets the base template class for compiled templates.
at line 141
public
enableDebug()
Enables debugging mode.
at line 149
public
disableDebug()
Disables debugging mode.
at line 159
public Boolean
isDebug()
Checks if debug mode is enabled.
at line 167
public
enableAutoReload()
Enables the auto_reload option.
at line 175
public
disableAutoReload()
Disables the auto_reload option.
at line 185
public Boolean
isAutoReload()
Checks if the auto_reload option is enabled.
at line 193
public
enableStrictVariables()
Enables the strict_variables option.
at line 201
public
disableStrictVariables()
Disables the strict_variables option.
at line 211
public Boolean
isStrictVariables()
Checks if the strict_variables option is enabled.
at line 221
public string|false
getCache()
Gets the cache directory or false if cache is disabled.
at line 232
public
setCache(string|false $cache)
Sets the cache directory or false if cache is disabled.
at line 244
public string
getCacheFilename(string $name)
Gets the cache filename for a given template.
at line 263
public string
getTemplateClass(string $name, integer $index = null)
Gets the template class associated with the given string.
at line 273
public string
getTemplateClassPrefix()
Gets the template class prefix.
at line 286
public string
render(string $name, array $context = array())
Renders a template.
at line 297
public
display(string $name, array $context = array())
Displays a template.
at line 310
public Twig_TemplateInterface
loadTemplate(string $name, integer $index = null)
Loads a template by name.
at line 349
public Boolean
isTemplateFresh(string $name, timestamp $time)
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.
at line 361
public
resolveTemplate($names)
at line 388
public
clearTemplateCache()
Clears the internal template cache.
at line 396
public
clearCacheFiles()
Clears the template cache files on the filesystem.
at line 414
public Twig_LexerInterface
getLexer()
Gets the Lexer instance.
at line 428
public
setLexer(Twig_LexerInterface $lexer)
Sets the Lexer instance.
at line 441
public Twig_TokenStream
tokenize(string $source, string $name = null)
Tokenizes a source code.
at line 451
public Twig_ParserInterface
getParser()
Gets the Parser instance.
at line 465
public
setParser(Twig_ParserInterface $parser)
Sets the Parser instance.
at line 477
public Twig_Node_Module
parse(Twig_TokenStream $tokens)
Parses a token stream.
at line 487
public Twig_CompilerInterface
getCompiler()
Gets the Compiler instance.
at line 501
public
setCompiler(Twig_CompilerInterface $compiler)
Sets the Compiler instance.
at line 513
public string
compile(Twig_NodeInterface $node)
Compiles a Node.
at line 526
public string
compileSource(string $source, string $name = null)
Compiles a template source code.
at line 543
public
setLoader(Twig_LoaderInterface $loader)
Sets the Loader instance.
at line 553
public Twig_LoaderInterface
getLoader()
Gets the Loader instance.
at line 567
public
setCharset(string $charset)
Sets the default template charset.
at line 577
public string
getCharset()
Gets the default template charset.
at line 585
public
initRuntime()
Initializes the runtime environment.
at line 601
public Boolean
hasExtension(string $name)
Returns true if the given extension is registered.
at line 613
public Twig_ExtensionInterface
getExtension(string $name)
Gets an extension by name.
at line 627
public
addExtension(Twig_ExtensionInterface $extension)
Registers an extension.
at line 645
public
removeExtension(string $name)
Removes an extension by name.
This method is deprecated and you should not use it.
at line 659
public
setExtensions(array $extensions)
Registers an array of extensions.
at line 671
public array
getExtensions()
Returns all registered extensions.
at line 681
public
addTokenParser(Twig_TokenParserInterface $parser)
Registers a Token Parser.
at line 695
public Twig_TokenParserBrokerInterface
getTokenParsers()
Gets the registered Token Parsers.
at line 711
public Twig_TokenParserInterface[]
getTags()
Gets registered tags.
Be warned that this method cannot return tags defined by Twig_TokenParserBrokerInterface classes.
at line 728
public
addNodeVisitor(Twig_NodeVisitorInterface $visitor)
Registers a Node Visitor.
at line 742
public Twig_NodeVisitorInterface[]
getNodeVisitors()
Gets the registered Node Visitors.
at line 757
public
addFilter(string|Twig_SimpleFilter $name, Twig_FilterInterface|Twig_SimpleFilter $filter = null)
Registers a Filter.
at line 785
public Twig_Filter|false
getFilter(string $name)
Get a filter by name.
Subclasses may override this method and load filters differently; so no list of filters is available.
at line 817
public
registerUndefinedFilterCallback($callable)
at line 831
public Twig_FilterInterface[]
getFilters()
Gets the registered Filters.
Be warned that this method cannot return filters defined with registerUndefinedFunctionCallback.
at line 846
public
addTest(string|Twig_SimpleTest $name, Twig_TestInterface|Twig_SimpleTest $test = null)
Registers a Test.
at line 869
public Twig_TestInterface[]
getTests()
Gets the registered Tests.
at line 885
public Twig_Test|false
getTest(string $name)
Gets a test by name.
at line 904
public
addFunction(string|Twig_SimpleFunction $name, Twig_FunctionInterface|Twig_SimpleFunction $function = null)
Registers a Function.
at line 932
public Twig_Function|false
getFunction(string $name)
Get a function by name.
Subclasses may override this method and load functions differently; so no list of functions is available.
at line 964
public
registerUndefinedFunctionCallback($callable)
at line 978
public Twig_FunctionInterface[]
getFunctions()
Gets registered functions.
Be warned that this method cannot return functions defined with registerUndefinedFunctionCallback.
at line 996
public
addGlobal(string $name, mixed $value)
Registers a Global.
New globals can be added before compiling or rendering a template; but after, you can only update existing globals.
at line 1023
public array
getGlobals()
Gets the registered Globals.
at line 1043
public array
mergeGlobals(array $context)
Merges a context with the defined globals.
at line 1061
public array
getUnaryOperators()
Gets the registered unary Operators.
at line 1075
public array
getBinaryOperators()
Gets the registered binary Operators.
at line 1084
public
computeAlternatives($name, $items)