Loaders
liquid2.loader.BaseLoader
Bases: ABC
Base class for all template loaders.
get_source
abstractmethod
get_source(
env: Environment,
template_name: str,
*,
context: RenderContext | None = None,
**kwargs: object
) -> TemplateSource
Get source information for a template.
PARAMETER | DESCRIPTION |
---|---|
env
|
The
TYPE:
|
template_name
|
A name or identifier for a template's source text.
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:
|
get_source_async
async
get_source_async(
env: Environment,
template_name: str,
*,
context: RenderContext | None = None,
**kwargs: object
) -> TemplateSource
An async version of get_source
.
The default implementation delegates to get_source()
.
load
load(
env: Environment,
name: str,
*,
globals: Mapping[str, object] | None = None,
context: RenderContext | None = None,
**kwargs: object
) -> Template
Find and parse template source code.
PARAMETER | DESCRIPTION |
---|---|
env
|
The
TYPE:
|
name
|
A name or identifier for a template's source text.
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:
|
liquid2.loader.TemplateSource
Bases: NamedTuple
A Liquid template source as returned by the get_source
method of a loader
.
ATTRIBUTE | DESCRIPTION |
---|---|
source |
The liquid template source code.
TYPE:
|
name |
The liquid template file name or other string identifying its origin.
TYPE:
|
uptodate |
Optional callable that will return
TYPE:
|
matter |
Optional mapping containing variables associated with the template. Could be "front matter" or other meta data.
TYPE:
|
liquid2.FileSystemLoader
Bases: BaseLoader
A loader that loads templates from one or more directories on the file system.
PARAMETER | DESCRIPTION |
---|---|
search_path
|
One or more paths to search.
TYPE:
|
encoding
|
Encoding to use when opening files.
TYPE:
|
ext
|
A default file extension. Should include a leading period.
TYPE:
|
get_source
get_source(
env: Environment,
template_name: str,
*,
context: RenderContext | None = None,
**kwargs: object
) -> TemplateSource
Get source information for a template.
liquid2.CachingFileSystemLoader
Bases: CachingLoaderMixin
, FileSystemLoader
A file system loader that caches parsed templates in memory.
PARAMETER | DESCRIPTION |
---|---|
search_path
|
One or more paths to search.
TYPE:
|
encoding
|
Open template files with the given encoding.
TYPE:
|
ext
|
A default file extension. Should include a leading period.
TYPE:
|
auto_reload
|
If
TYPE:
|
namespace_key
|
The name of a global render context variable or loader keyword argument that resolves to the current loader "namespace" or "scope". If you're developing a multi-user application, a good namespace might be
TYPE:
|
capacity
|
The maximum number of templates to hold in the cache before removing the least recently used template.
TYPE:
|
liquid2.DictLoader
Bases: BaseLoader
A loader that loads templates from a dictionary.
PARAMETER | DESCRIPTION |
---|---|
templates
|
A dictionary mapping template names to template source strings.
TYPE:
|
liquid2.CachingDictLoader
liquid2.PackageLoader
Bases: BaseLoader
A template loader that reads templates from Python packages.
PARAMETER | DESCRIPTION |
---|---|
package
|
Import name of a package containing Liquid templates.
TYPE:
|
package_path
|
One or more directories in the package containing Liquid templates.
TYPE:
|
encoding
|
Encoding of template files.
TYPE:
|
ext
|
A default file extension to use if one is not provided. Should include a leading period.
TYPE:
|
liquid2.ChoiceLoader
Bases: BaseLoader
A template loader that delegates to other template loaders.
PARAMETER | DESCRIPTION |
---|---|
loaders
|
A list of loaders implementing
TYPE:
|
liquid2.CachingChoiceLoader
Bases: CachingLoaderMixin
, ChoiceLoader
A ChoiceLoader
that caches parsed templates in memory.
PARAMETER | DESCRIPTION |
---|---|
loaders
|
A list of loaders implementing
TYPE:
|
auto_reload
|
If
TYPE:
|
namespace_key
|
The name of a global render context variable or loader keyword argument that resolves to the current loader "namespace" or "scope".
TYPE:
|
capacity
|
The maximum number of templates to hold in the cache before removing the least recently used template.
TYPE:
|
liquid2.CachingLoaderMixin
Bases: ABC
, _CachingLoaderProtocol
A mixin class that adds caching to a template loader.