Skip to main content

Loader

This class provides a mechanism for loading templates directly from a dictionary of strings. It maps template names to their corresponding content and yields origin objects for template discovery within the engine. This is primarily used for in-memory template storage where filesystem access is not required.

Attributes

AttributeTypeDescription
templates_dictdictA dictionary mapping template names to their string contents, used as the primary data source for template retrieval.

Constructor

Signature

def Loader(
engine: Any,
templates_dict: dict
) - > null

Parameters

NameTypeDescription
engineAnyThe template engine instance.
templates_dictdictA dictionary mapping template names to their contents.

Signature

def Loader(
engine: [Engine](../../engine/engine.md?sid=django_template_engine_engine),
templates_dict: dict
)

Parameters

NameTypeDescription
engine[Engine](../../engine/engine.md?sid=django_template_engine_engine)The template engine instance associated with this loader.
templates_dictdictA dictionary where keys are template names and values are the raw template strings.

Methods


get_contents()

@classmethod
def get_contents(
origin: [Origin](../../base/origin.md?sid=django_template_base_origin)
) - > string

Fetches the raw content of a template based on the provided Origin object.

Parameters

NameTypeDescription
origin[Origin](../../base/origin.md?sid=django_template_base_origin)The Origin object containing the name of the template to retrieve.

Returns

TypeDescription
stringThe raw template source code associated with the origin's name.

get_template_sources()

@classmethod
def get_template_sources(
template_name: string
) - > generator

Generates Origin objects for the given template name to identify where the template should be loaded from.

Parameters

NameTypeDescription
template_namestringThe logical name of the template to locate.

Returns

TypeDescription
generatorA generator yielding an Origin instance configured with the template name and current loader.