diff --git a/core/unified_template/unified_template.py b/core/unified_template/unified_template.py index 1832ba03..fb353392 100644 --- a/core/unified_template/unified_template.py +++ b/core/unified_template/unified_template.py @@ -32,7 +32,18 @@ def __init__(self, input): elif isinstance(input, dict): if input.get("type") != UNIFIED_TEMPLATE_TYPE_NAME: raise Exception("template must be string or dict with type='{}'".format(UNIFIED_TEMPLATE_TYPE_NAME)) - self.template = jinja2.Template(input["template"], extensions=input.get("extensions", ())) + if input.get("file"): + from smart_kit.configs import get_app_config + app_config = get_app_config() + template_loader = jinja2.FileSystemLoader(app_config.JINJA2_TEMPLATES_PATH) + file_name = input["file"] + self.jinja2_environment = jinja2.Environment( + loader=template_loader, trim_blocks=True, lstrip_blocks=True + ) + self.template = self.jinja2_environment.get_template(file_name) + log("UnifiedTemplateLoader: File, file_name: %(file_name)s", params={"file_name": file_name}) + else: + self.template = jinja2.Template(input["template"], extensions=input.get("extensions", ())) self.loader = UnifiedTemplate.loaders[input.get("loader", "str")] self.support_templates = {k: UnifiedTemplate(t) for k, t in input.get("support_templates", dict()).items()} else: diff --git a/smart_kit/configs/__init__.py b/smart_kit/configs/__init__.py index 3d1b5c33..2a579f3f 100644 --- a/smart_kit/configs/__init__.py +++ b/smart_kit/configs/__init__.py @@ -41,6 +41,8 @@ def get_app_config(environment_variable=ENVIRONMENT_VARIABLE): set_default(app_config, "SECRET_PATH", os.path.join(static_path, "./configs")) references_path = os.path.join(static_path, "./references") set_default(app_config, "REFERENCES_PATH", references_path) + jinja2_templates_path = os.path.join(references_path, "./templates") + set_default(app_config, "JINJA2_TEMPLATES_PATH", jinja2_templates_path) set_default(app_config, "LOCAL_TESTING", CLInterface) set_default(app_config, "TEST_CASE", TestCase)