Render context
liquid.RenderContext
A template render context.
A new render context is created automatically each time BoundTemplate.render
is called, which includes globals
set on the bound liquid.Environment
and
liquid.template.BoundTemplate
.
assign
Add or replace the context variable named key with the value val.
copy
copy(
namespace: Mapping[str, object],
disabled_tags: Optional[list[str]] = None,
carry_loop_iterations: bool = False,
template: Optional[BoundTemplate] = None,
block_scope: bool = False,
) -> RenderContext
Return a copy of this render context.
Local variables and other state for stateful tags are not copied.
extend
extend(
namespace: Mapping[str, object],
template: Optional[BoundTemplate] = None,
) -> Iterator[RenderContext]
Extend this context with the given read-only namespace.
filter
Return the filter function with given name.
get
Resolve and return path in the current scope.
If token is not None, it will be used to give error messages extra contextual information.
Returns default is the path is not in scope.
get_async
async
Resolve and return path in the current scope.
If token is not None, it will be used to give error messages extra contextual information.
Returns default is the path is not in scope.
get_buffer
Return a new StringIO object that respects the configured stream limit.
get_item
An item getter used when resolving a Liquid path.
Override this to change the behavior of .first
, .last
and .size
.
get_item_async
async
An async item getter for resolving paths.
get_size_of_locals
Return the "size" or a "score" for the current local namespace.
This is used by the optional local namespace resource limit. Override
get_size_of_locals
to customize how the limit is calculated. Be sure
to consider self.local_namespace_size_carry
when writing a custom
implementation of get_size_of_locals
.
The default implementation uses sys.getsizeof()
on each of the local
namespace's values. It is not a reliable measure of size in bytes.
get_template_async
async
Load a template from the environment asynchronously.
loop
Just like Context.extend
, but keeps track of ForLoop objects too.
parentloop
Return the last ForLoop object from the loop stack.
raise_for_loop_limit
Raise a LoopIterationLimitError
if loop stack is bigger than the limit.
resolve
Return the object/value at name
in the current scope.
This is like get
, but does a single, top-level lookup rather than a
chained lookup from a sequence of keys.