Environment
liquid2.Environment
Template parsing and rendering configuration.
An Environment is where you might register custom tags and filters, or store
global context variables that should be included with every template.
| PARAMETER | DESCRIPTION |
|---|---|
loader
|
A template loader from which template source text will be read when
calling get_template or when rendering
with the built-in
TYPE:
|
globals
|
An optional mapping of template variables that will be added to the render context of all templates rendered from the environment.
TYPE:
|
auto_escape
|
If
TYPE:
|
undefined
|
The Undefined type used to represent template variables that don't exist. |
default_trim
|
The automatic whitespace stripping mode to use. This mode can then
be overridden by template authors per Liquid tag using whitespace control
symbols (
TYPE:
|
validate_filter_arguments
|
If
TYPE:
|
context_depth_limit
class-attribute
Maximum number of times a render context can be extended or wrapped before
raising a ContextDepthError.
default_trim
instance-attribute
The default whitespace trimming mode.
filters
instance-attribute
The environment's filter register, mapping filter names to callables.
lexer_class
class-attribute
instance-attribute
The lexer class to use when scanning template source text.
local_namespace_limit
class-attribute
Maximum number of bytes (according to sys.getsizeof) allowed in a template's
local namespace before a LocalNamespaceLimitError is raised. We only count the
size of the namespaces values, not the size of keys/names.
loop_iteration_limit
class-attribute
Maximum number of loop iterations allowed before a LoopIterationLimitError is
raised.
output_stream_limit
class-attribute
Maximum number of bytes that can be written to a template's output stream before
raising an OutputStreamLimitError.
shorthand_indexes
class-attribute
instance-attribute
If True, array indexes can be separated by dots without enclosing square
brackets. The default is False.
suppress_blank_control_flow_blocks
class-attribute
instance-attribute
If True (the default), indicates that blocks rendering to whitespace only will not be output.
tags
instance-attribute
The environment's tag register, mapping tag names to instances of Tag.
template_class
class-attribute
instance-attribute
The template class to use after parsing source text.
from_string
from_string(
source: str,
*,
name: str = "",
path: str | Path | None = None,
globals: Mapping[str, object] | None = None,
overlay_data: Mapping[str, object] | None = None
) -> Template
Create a template from a string.
get_template
get_template(
name: str,
*,
globals: Mapping[str, object] | None = None,
context: RenderContext | None = None,
**kwargs: object
) -> Template
Load and parse a template using the configured loader.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The template's name. The loader is responsible for interpreting the name. It could be the name of a file or some other identifier.
TYPE:
|
globals
|
A mapping of render context variables attached to the resulting template.
TYPE:
|
context
|
An optional render context that can be used to narrow the template source search space.
TYPE:
|
kwargs
|
Arbitrary arguments that can be used to narrow the template source search space.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TemplateNotFound
|
If a template with the given name can not be found. |
get_template_async
async
get_template_async(
name: str,
*,
globals: Mapping[str, object] | None = None,
context: RenderContext | None = None,
**kwargs: object
) -> Template
An async version of get_template().
make_globals
Combine environment globals with template globals.
parse
Compile template source text and return an abstract syntax tree.
setup_tags_and_filters
Add tags and filters to this environment.
This is called once when initializing an environment. Override this method in your custom environments.
tokenize
Scan Liquid template source and return a list of Markup objects.