Skip to content

Template

liquid2.Template

A parsed template ready to be rendered.

Don't try to instantiate Template directly. Use parse(), Environment.from_string() or Environment.get_template() instead.

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

Return False if the template has been modified, True otherwise.

is_up_to_date_async async

is_up_to_date_async() -> bool

An async version of is_up_to_date().

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.

render

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

Render this template with args and kwargs added to the render context.

args and kwargs are passed to dict().

render_async async

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

Render this template with args and kwargs added to the render context.

args and kwargs are passed to dict().

render_with_context

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

Render this template using an existing render context and output buffer.

render_with_context_async async

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

Render this template using an existing render context and output buffer.

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 also 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 also 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.

liquid2.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]]

liquid2.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.

liquid2.static_analysis.Span dataclass

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

end instance-attribute

end: int

A stop index into the template source text.

start instance-attribute

start: int

A start index into the template source text.

template_name instance-attribute

template_name: str

The template name.