Craft 3 Class Reference

Class craft\web\twig\Environment

Inheritance
craft\web\twig\Environment ยป Twig_Environment
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/web/twig/Environment.php

Base Twig template class.

Public Methods
Method Description Defined By
__construct() Constructor. craft\web\twig\Environment
addExtension() Twig_Environment
addFilter() Twig_Environment
addFunction() Twig_Environment
addGlobal() Registers a Global. Twig_Environment
addNodeVisitor() Twig_Environment
addRuntimeLoader() Adds a runtime loader. Twig_Environment
addTest() Registers a Test. Twig_Environment
addTokenParser() Twig_Environment
compile() Compiles a node and returns the PHP code. Twig_Environment
compileSource() Compiles a template source code. craft\web\twig\Environment
createTemplate() Creates a template from source. Twig_Environment
disableAutoReload() Disables the auto_reload option. Twig_Environment
disableDebug() Disables debugging mode. Twig_Environment
disableStrictVariables() Disables the strict_variables option. Twig_Environment
display() Displays a template. Twig_Environment
enableAutoReload() Enables the auto_reload option. Twig_Environment
enableDebug() Enables debugging mode. Twig_Environment
enableStrictVariables() Enables the strict_variables option. Twig_Environment
getBaseTemplateClass() Gets the base template class for compiled templates. Twig_Environment
getBinaryOperators() Gets the registered binary Operators. Twig_Environment
getCache() Gets the current cache implementation. Twig_Environment
getCharset() Gets the default template charset. Twig_Environment
getDefaultEscaperStrategy() Returns the default escaper strategy to use based on the template name. craft\web\twig\Environment
getExtension() Gets an extension by class name. Twig_Environment
getExtensions() Returns all registered extensions. Twig_Environment
getFilter() Get a filter by name. Twig_Environment
getFilters() Gets the registered Filters. Twig_Environment
getFunction() Get a function by name. Twig_Environment
getFunctions() Gets registered functions. Twig_Environment
getGlobals() Gets the registered Globals. Twig_Environment
getLoader() Gets the Loader instance. Twig_Environment
getNodeVisitors() Gets the registered Node Visitors. Twig_Environment
getRuntime() Returns the runtime implementation of a Twig element (filter/function/test). Twig_Environment
getTags() Gets registered tags. Twig_Environment
getTemplateClass() Gets the template class associated with the given string. Twig_Environment
getTest() Gets a test by name. Twig_Environment
getTests() Gets the registered Tests. Twig_Environment
getTokenParsers() Gets the registered Token Parsers. Twig_Environment
getUnaryOperators() Gets the registered unary Operators. Twig_Environment
hasExtension() Returns true if the given extension is registered. Twig_Environment
isAutoReload() Checks if the auto_reload option is enabled. Twig_Environment
isDebug() Checks if debug mode is enabled. Twig_Environment
isStrictVariables() Checks if the strict_variables option is enabled. Twig_Environment
isTemplateFresh() Returns true if the template is still fresh. Twig_Environment
load() Loads a template. Twig_Environment
loadTemplate() Loads a template internal representation. craft\web\twig\Environment
mergeGlobals() Merges a context with the defined globals. Twig_Environment
parse() Converts a token stream to a node tree. Twig_Environment
registerUndefinedFilterCallback() Twig_Environment
registerUndefinedFunctionCallback() Twig_Environment
render() Renders a template. Twig_Environment
resolveTemplate() Tries to load a template consecutively from an array. Twig_Environment
setBaseTemplateClass() Sets the base template class for compiled templates. Twig_Environment
setCache() Sets the current cache implementation. Twig_Environment
setCharset() Sets the default template charset. Twig_Environment
setCompiler() Twig_Environment
setDefaultEscaperStrategy() craft\web\twig\Environment
setExtensions() Registers an array of extensions. Twig_Environment
setLexer() Twig_Environment
setLoader() Twig_Environment
setParser() Twig_Environment
tokenize() Tokenizes a source code. Twig_Environment
Constants
Constant Value Description Defined By
EXTRA_VERSION '' Twig_Environment
MAJOR_VERSION 2 Twig_Environment
MINOR_VERSION 4 Twig_Environment
RELEASE_VERSION 7 Twig_Environment
VERSION '2.4.7' Twig_Environment
VERSION_ID 20407 Twig_Environment

Method Details

__construct() public method #

Constructor.

Available options:

public void __construct ( Twig_LoaderInterface $loader, array $options = [] )
$loader Twig_LoaderInterface
$options array An array of options

compileSource() public method #

Compiles a template source code.

public string compileSource ( Twig_Source $source )
$source
return string The compiled PHP source code
throws Twig_Error_Syntax When there was an error during tokenizing, parsing or compiling

getDefaultEscaperStrategy() public method #

Returns the default escaper strategy to use based on the template name.

public string, false getDefaultEscaperStrategy ( \craft\web\twig\string $name )
$name string

loadTemplate() public method #

Loads a template internal representation.

This method is for internal use only and should never be called directly.

public Twig_Template loadTemplate ( $name, $index null )
$name string The template name
$index integer The index if it is an embedded template
return Twig_Template A template instance representing the given template name
throws Twig_Error_Loader When the template cannot be found
throws Twig_Error_Runtime When a previously generated cache is corrupted
throws Twig_Error_Syntax When an error occurred during compilation

setDefaultEscaperStrategy() public method #

public void setDefaultEscaperStrategy ( $strategy null )
$strategy