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
| Attribute | Type | Description |
|---|---|---|
| templates_dict | dict | A 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
| Name | Type | Description |
|---|---|---|
| engine | Any | The template engine instance. |
| templates_dict | dict | A dictionary mapping template names to their contents. |
Signature
def Loader(
engine: [Engine](../../engine/engine.md?sid=django_template_engine_engine),
templates_dict: dict
)
Parameters
| Name | Type | Description |
|---|---|---|
| engine | [Engine](../../engine/engine.md?sid=django_template_engine_engine) | The template engine instance associated with this loader. |
| templates_dict | dict | A 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
| Name | Type | Description |
|---|---|---|
| origin | [Origin](../../base/origin.md?sid=django_template_base_origin) | The Origin object containing the name of the template to retrieve. |
Returns
| Type | Description |
|---|---|
string | The 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
| Name | Type | Description |
|---|---|---|
| template_name | string | The logical name of the template to locate. |
Returns
| Type | Description |
|---|---|
generator | A generator yielding an Origin instance configured with the template name and current loader. |