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.
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:
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):
* 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).
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 |