Skip to content

Template

liquid.BoundTemplate

A liquid template that has been parsed and is bound to a liquid.Environment.

You probably don't want to instantiate BoundTemplate directly. Use liquid.Environment.from_string() or liquid.Environment.get_template() instead.

PARAMETER DESCRIPTION
env

The environment this template is bound to.

TYPE: Environment

nodes

The parse tree representing this template.

TYPE: list[Node]

name

Optional name of the template. Defaults to an empty string.

TYPE: str DEFAULT: ''

path

Optional origin path or identifier for the template.

TYPE: Optional[Union[str, Path]] DEFAULT: None

globals

An optional mapping of context variables made available every time the resulting template is rendered. Defaults to None.

TYPE: Optional[Mapping[str, object]] DEFAULT: None

matter

Optional mapping containing variables associated with the template. Could be "front matter" or other meta data.

TYPE: Optional[Mapping[str, object]] DEFAULT: None

uptodate

Optional callable that will return True if the template is up to date, or False if it needs to be reloaded. Defaults to None.

TYPE: UpToDate DEFAULT: None

analyze

analyze(
    *, include_partials: bool = True
) -> TemplateAnalysis

Statically analyze this template and any included/rendered templates.

PARAMETER DESCRIPTION
include_partials

If True, we will try to load partial templates and analyze those templates too.

TYPE: bool DEFAULT: True

analyze_async async

analyze_async(
    *, include_partials: bool = True
) -> TemplateAnalysis

An async version of analyze.

filter_names

filter_names(*, include_partials: bool = True) -> list[str]

Return a list of filter names used in this template.

filter_names_async async

filter_names_async(
    *, include_partials: bool = True
) -> list[str]

Return a list of filter names used in this template.

full_name

full_name() -> str

Return this template's path, if available, joined with its name.

global_variable_paths

global_variable_paths(
    *, include_partials: bool = True
) -> list[str]

Return a list of variables used in this template including all path segments.

Excludes variables that are local to the template, like those crated with {% assign %} and {% capture %}.

PARAMETER DESCRIPTION
include_partials

If True, will try to load and find variables in included/rendered templates too.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[str]

A list of distinct paths for variables in this template.

global_variable_paths_async async

global_variable_paths_async(
    *, include_partials: bool = True
) -> list[str]

Return a list of variables used in this template including all path segments.

Excludes variables that are local to the template, like those crated with {% assign %} and {% capture %}.

PARAMETER DESCRIPTION
include_partials

If True, will try to load and find variables in included/rendered templates too.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[str]

A list of distinct paths for variables in this template.

global_variable_segments

global_variable_segments(
    *, include_partials: bool = True
) -> list[Segments]

Return a list of variables used in this template, each as a list of segments.

Excludes variables that are local to the template, like those crated with {% assign %} and {% capture %}.

PARAMETER DESCRIPTION
include_partials

If True, will try to load and find variables in included/rendered templates too.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[Segments]

A list of distinct paths for variables in this template.

global_variable_segments_async async

global_variable_segments_async(
    *, include_partials: bool = True
) -> list[Segments]

Return a list of variables used in this template, each as a list of segments.

Excludes variables that are local to the template, like those crated with {% assign %} and {% capture %}.

PARAMETER DESCRIPTION
include_partials

If True, will try to load and find variables in included/rendered templates too.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[Segments]

A list of distinct paths for variables in this template.

global_variables

global_variables(
    *, include_partials: bool = True
) -> list[str]

Return a list of variables used in this template without path segments.

Excludes variables that are local to the template, like those crated with {% assign %} and {% capture %}.

PARAMETER DESCRIPTION
include_partials

If True, will try to load and find variables in included/rendered templates too.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[str]

A list of distinct root segments for variables in this template.

global_variables_async async

global_variables_async(
    *, include_partials: bool = True
) -> list[str]

Return a list of variables used in this template without path segments.

Excludes variables that are local to the template, like those crated with {% assign %} and {% capture %}.

PARAMETER DESCRIPTION
include_partials

If True, will try to load and find variables in included/rendered templates too.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[str]

A list of distinct root segments for variables in this template.

is_up_to_date

is_up_to_date() -> bool

False if the template has bee modified, True otherwise.

is_up_to_date_async async

is_up_to_date_async() -> bool

An async version of the is_up_to_date property.

If template.uptodate is a coroutine, it wil be awaited. Otherwise it will be called just like is_up_to_date

make_globals

make_globals(
    render_args: Mapping[str, object],
) -> Mapping[str, object]

Return a mapping including render arguments and template globals.

make_partial_namespace

make_partial_namespace(
    partial: bool, render_args: Mapping[str, object]
) -> Mapping[str, object]

Return a namespace dictionary.

This is used by render_with_context to extend an existing context.

render

render(*args: Any, **kwargs: Any) -> str

Render the template with args and kwargs included in the render context.

Accepts the same arguments as the dict constructor.

render_async async

render_async(*args: Any, **kwargs: Any) -> str

An async version of liquid.template.BoundTemplate.render.

render_with_context

render_with_context(
    context: RenderContext,
    buffer: TextIO,
    *args: Any,
    partial: bool = False,
    block_scope: bool = False,
    **kwargs: Any
) -> None

Render the template using an existing context and output buffer.

PARAMETER DESCRIPTION
context

A render context.

TYPE: RenderContext

buffer

File-like object to which rendered text is written.

TYPE: TextIO

partial

If True, indicates that the current template has been included using either a "render" or "include" tag. Defaults to False.

TYPE: bool DEFAULT: False

block_scope

If True, indicates that assigns, breaks and continues from this template will not leak into the parent context. Defaults to False.

TYPE: bool DEFAULT: False

args

Passed to the dict constructor. The resulting dictionary is added to the render context.

TYPE: Any DEFAULT: ()

kwargs

Passed to the dict constructor. The resulting dictionary is added to the render context.

TYPE: Any DEFAULT: {}

render_with_context_async async

render_with_context_async(
    context: RenderContext,
    buffer: TextIO,
    *args: Any,
    partial: bool = False,
    block_scope: bool = False,
    **kwargs: Any
) -> None

An async version of render_with_context.

tag_names

tag_names(*, include_partials: bool = True) -> list[str]

Return a list of tag names used in this template.

tag_names_async async

tag_names_async(
    *, include_partials: bool = True
) -> list[str]

Return a list of tag names used in this template.

variable_paths

variable_paths(
    *, include_partials: bool = True
) -> list[str]

Return a list of variables used in this template including all path segments.

Includes variables that are local to the template, like those crated with {% assign %} and {% capture %}.

See also global_variable_paths.

PARAMETER DESCRIPTION
include_partials

If True, will try to load and find variables in included/rendered templates too.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[str]

A list of distinct paths for variables in this template.

variable_paths_async async

variable_paths_async(
    *, include_partials: bool = True
) -> list[str]

Return a list of variables used in this template including all path segments.

Includes variables that are local to the template, like those crated with {% assign %} and {% capture %}.

See also global_variable_paths.

PARAMETER DESCRIPTION
include_partials

If True, will try to load and find variables in included/rendered templates too.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[str]

A list of distinct paths for variables in this template.

variable_segments

variable_segments(
    *, include_partials: bool = True
) -> list[Segments]

Return a list of variables used in this template, each as a list of segments.

Includes variables that are local to the template, like those crated with {% assign %} and {% capture %}.

See global_variable_segments.

PARAMETER DESCRIPTION
include_partials

If True, will try to load and find variables in included/rendered templates too.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[Segments]

A list of distinct paths for variables in this template.

variable_segments_async async

variable_segments_async(
    *, include_partials: bool = True
) -> list[Segments]

Return a list of variables used in this template, each as a list of segments.

Includes variables that are local to the template, like those crated with {% assign %} and {% capture %}.

See global_variable_segments.

PARAMETER DESCRIPTION
include_partials

If True, will try to load and find variables in included/rendered templates too.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[Segments]

A list of distinct paths for variables in this template.

variables

variables(*, include_partials: bool = True) -> list[str]

Return a list of variables used in this template without path segments.

Includes variables that are local to the template, like those crated with {% assign %} and {% capture %}.

See also global_variables.

PARAMETER DESCRIPTION
include_partials

If True, will try to load and find variables in included/rendered templates too.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[str]

A list of distinct root segments for variables in this template.

variables_async async

variables_async(
    *, include_partials: bool = True
) -> list[str]

Return a list of variables used in this template without path segments.

Includes variables that are local to the template, like those crated with {% assign %} and {% capture %}.

See also global_variables.

PARAMETER DESCRIPTION
include_partials

If True, will try to load and find variables in included/rendered templates too.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
list[str]

A list of distinct root segments for variables in this template.

liquid.static_analysis.TemplateAnalysis dataclass

The result of analyzing a template using Template.analyze().

PARAMETER DESCRIPTION
variables

All referenced variables, whether they are in scope or not. Including references to names such as forloop from the for tag.

TYPE: dict[str, list[Variable]]

locals

Template variables that are added to the template local scope, whether they are subsequently used or not.

TYPE: dict[str, list[Variable]]

globals

Template variables that, on the given line number and "file", are out of scope or are assumed to be "global". That is, expected to be included by the application developer rather than a template author.

TYPE: dict[str, list[Variable]]

filters

All filters found during static analysis.

TYPE: dict[str, list[Span]]

tags

All tags found during static analysis.

TYPE: dict[str, list[Span]]

liquid.static_analysis.Variable dataclass

A variable as sequence of segments that make up its path and its location.

Variables with the same segments compare equal, regardless of span.

segments instance-attribute

segments: Segments

The variable's segments.

span class-attribute instance-attribute

span: Span = field(hash=False, compare=False)

The variable's location.

liquid.static_analysis.Span dataclass

The location of a variable, tag or filter in a template.

index instance-attribute

index: int

A start index into the template source text.

template_name instance-attribute

template_name: str

The template name.

line_col

line_col(source: str) -> tuple[int, int]

Return a tuple of (line number, column number) for this span in source.