Environment class base
The core component of Jinja 2 is the Environment.
It contains important shared variables like configuration, filters, tests and others.
Environment modifications can break templates that have been parsed or loaded.
Constructors
-
Environment({String commentStart = '{#', String commentEnd = '#}', String variableStart = '{{', String variableEnd = '}}', String blockStart = '{%', String blockEnd = '%}', String? lineCommentPrefix, String? lineStatementPrefix, bool leftStripBlocks = false, bool trimBlocks = false, String newLine = '\n', bool keepTrailingNewLine = false, bool optimize = true, Function finalize = defaults.finalize, Loader? loader, bool autoReload = true, Map<
String, Object?> ? globals, Map<String, Function> ? filters, Map<String, Function> ? tests, List<Node Function(Node)> ? modifiers, Map<String, Template> ? templates, Random? random, AttributeGetter? getAttribute, ItemGetter getItem = defaults.getItem}) - The core component of Jinja 2 is the Environment.
Properties
- autoReload → bool
-
Some loaders load templates from locations where the template
sources may change (ie: file system or database).
final
- blockEnd → String
-
The string marking the end of a block
final
- blockStart → String
-
The string marking the beginning of a block.
final
- commentEnd → String
-
The string marking the end of a comment.
final
- commentStart → String
-
The string marking the beginning of a comment.
final
-
filters
→ Map<
String, Function> -
A map of filters that are available in every template loaded by
the environment.
final
- finalize → ContextFinalizer
-
A Function that can be used to process the result of a variable
expression before it is output.
final
- getAttribute → AttributeGetter
-
Get an attribute of an object.
final
- getItem → ItemGetter
-
Get an item from an object.
final
-
globals
→ Map<
String, Object?> -
A map of variables that are available in every template loaded by
the environment.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- keepTrailingNewLine → bool
-
Preserve the trailing newline when rendering templates.
The default is
false
, which causes a single newline, if present, to be stripped from the end of the template.final - leftStripBlocks → bool
-
If this is set to
true
leading spaces and tabs are stripped from the start of a line to a block.final - lexer → Lexer
-
The
Lexer
for this environment.no setter - lineCommentPrefix → String?
-
If given and a string, this will be used as prefix for line based
comments.
final
- lineStatementPrefix → String?
-
If given and a string, this will be used as prefix for line based
statements.
final
- loader → Loader?
-
The template loader for this environment.
final
-
modifiers
→ List<
Node Function(Node)> -
A list of template modifiers.
final
- newLine → String
-
The sequence that starts a newline.
final
- optimize → bool
-
Should the optimizer be enabled?
final
- random → Random
-
A random generator used by some filters.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
templates
→ Map<
String, Template> -
A map of parsed templates loaded by the environment.
final
-
tests
→ Map<
String, Function> -
A map of tests that are available in every template loaded by
the environment.
final
- trimBlocks → bool
-
If this is set to
true
the first newline after a block is removed (block, not variable tag!).final - variableEnd → String
-
The string marking the end of a print statement.
final
- variableStart → String
-
The string marking the beginning of a print statement.
final
Methods
-
callCommon(
Function function, List< Object?> positional, Map<Symbol, Object?> named, Context? context) → Object? - Common filter and test caller.
-
callFilter(
String name, List< Object?> positional, [Map<Symbol, Object?> named = const <Symbol, Object?>{}, Context? context]) → Object? -
If
name
filter not found TemplateRuntimeError thrown. -
callTest(
String name, List< Object?> positional, [Map<Symbol, Object?> named = const <Symbol, Object?>{}, Context? context]) → bool -
If
name
not found throws TemplateRuntimeError. -
fromString(
String source, {String? path, Map< String, Object?> ? globals}) → Template - Load a template from a source string without using loader.
-
getTemplate(
String name) → Template -
Load a template by name with
loader
and return a Template. -
lex(
String source, {String? path}) → Iterable< Token> - Lex the given source and return a list of tokens.
-
listTemplates(
) → List< String> - Returns a list of templates for this environment.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parse(
String source, {String? path}) → Node - Parse the source code and return the AST node.
-
scan(
Iterable< Token> tokens, {String? path}) → Node - Parse the list of tokens and return the AST node.
-
selectTemplate(
List< Object?> names) → Template - Load a template from a list of names.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override